Chloe
Chloe

Reputation: 26274

How do I enable page caching in Yii? It's not working

How do I enable page caching in Yii? I followed the documentation, but it's not working.
http://www.yiiframework.com/doc-2.0/guide-caching-page.html
http://www.yiiframework.com/doc-2.0/guide-structure-filters.html#pagecache

class SiteController extends Controller {
    public function behaviors() {
        return [
            'pageCache' => [
              'class' => 'yii\filters\PageCache',
              'only' => ['index'],
              'duration' => 10*60,
              'variations' => [
                  \Yii::$app->language,
              ],
Server response
HTTP/1.1 200 OK
Date: Thu, 02 Apr 2015 01:25:06 GMT
Server: Apache/2.2.29 (Unix) mod_ssl/2.2.29 OpenSSL/1.0.2a DAV/2 PHP/5.6.7
X-Powered-By: PHP/5.6.7
Set-Cookie: ...cookies...
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 4750
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8

Notice there is no Cache-Control:max-age= or Expires: heading. If I change the class to xPageCache then it does fail with an error, so it's reading the settings.

Upvotes: 1

Views: 1392

Answers (1)

Chloe
Chloe

Reputation: 26274

It was working. I had to update the design of the page and it would not show the changes after reload. It seems to be a server side rendering cache, not a HTTP browser cache. So it saves rendering the page, but not the request/response to the server.

Upvotes: 0

Related Questions