如何在Yii中启用页面缓存?我按照文档,但它不工作。
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
请注意,没有Cache-Control:max-age=
或Expires:
标题。如果我将类更改为xPageCache
,那么它会因错误而失败,因此它正在读取设置。
答案 0 :(得分:0)
它正在运作。我不得不更新页面的设计,重新加载后不会显示更改。它似乎是服务器端渲染缓存,而不是HTTP浏览器缓存。因此它保存了呈现页面,但不保存对服务器的请求/响应。