Note that there are some explanatory texts on larger screens.

plurals
  1. POCakePHP 2.1: Browser cache vs View cache
    primarykey
    data
    text
    <p>I have a question about the way view caching and browser caching work together in CakePHP 2.1.</p> <p>I've just upgraded my app to CakePHP 2.1, and set up HTTP caching using the new <code>$this-&gt;response-&gt;modified</code> method (which works well):</p> <pre><code>class ArticlesController extends AppController { public function view($id) { $article = $this-&gt;Article-&gt;find( 'first', array('conditions' =&gt; array('Article.id' =&gt; $id)) ); $this-&gt;response-&gt;modified($article['Article']['modified']); $this-&gt;set(compact('article')); } } </code></pre> <p>I have also set up CakePHP view caching:</p> <pre><code>class ArticlesController extends AppController { public $cacheAction = array( 'view' =&gt; array('callbacks' =&gt; true, 'duration' =&gt; "1 week"), } } </code></pre> <p>Both work well when used independently. However, when both are enabled, the CakePHP view caching seems to override the browser caching (specifically, no <code>Last-Modified</code> header is sent when pages are served from the CakePHP view cache). This stops the browser from caching pages that are being served from CakePHP's view cache.</p> <p>Ideally, I would like the browser to cache pages even if they are being served from CakePHP's cache (i.e. I would like CakePHP to return a <code>Last-Modified</code> header, and respond to the browser's <code>If-Modified-Since</code> request header, regardless of whether CakePHP has is returning a cached copy of page or not).</p> <p>I'm just wondering whether this is expected behavior, whether I'm doing something wrong, or whether it's something that has not been considered (or is not thought to be important).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload