如何在 CakePHP 中打开缓存?
我正在使用 CakePHP。我在控制器中有一个操作,可以生成应用程序的静态内容页面。我想缓存整个操作/视图。控制器是 Pages,操作是 Main。我没有看到视图的缓存文件出现在 tmp/cache 文件夹中。
我取消了 core.php 中 Cache.check 设置的注释,因此它显示为:
Configure::write('Cache.check', true);
我已将缓存助手添加到页面控制器中:
var $helpers = array('javascript','cache');
我已经告诉控制器缓存名为“main”的操作:
var $cacheAction = array('main/'=>86400);
我已经确认从今天起 app/tmp/cache 文件夹中存在其他缓存文件(模型缓存),所以我知道这不是权限问题。
这是我的页面控制器的顶部:
var $name = 'Pages';
var $helpers = array('Javascript','Cache');
var $uses = array();
var $components = array('Authentication','Security');
var $cacheAction = array('main/'=>86400);
我不确定在 CachePHP 中启用视图缓存时缺少什么。我错过了什么吗?有什么想法吗?
I am using CakePHP. I have an action in a controller that produces the static content pages of an app. I want to cache this entire action/view. The controller is Pages and the action is Main. I am not seeing the cached files for the view appear in the tmp/cache folder.
I have uncommented the Cache.check setting in core.php, so it reads:
Configure::write('Cache.check', true);
I have added the cache helper to the pages controller:
var $helpers = array('javascript','cache');
I have told the controller to cache the action called "main":
var $cacheAction = array('main/'=>86400);
I have confirmed there are other cache files (the model cache) in the app/tmp/cache folder from today, so I know this isn't a permissions issue.
Here is the top of my pages controller:
var $name = 'Pages';
var $helpers = array('Javascript','Cache');
var $uses = array();
var $components = array('Authentication','Security');
var $cacheAction = array('main/'=>86400);
I am not sure what I am missing to enable the cache of a view in CachePHP. Am I missing something? Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
愚蠢的检查,抱歉,但只是为了确保:
将单词“javascript”和“cache”大写
,即
var $helpers = array('Javascript','Cache');
不像你粘贴的那样。确保您已添加
var $cacheAction = array('main/'=>86400);
和var $helpers = array('Javascript','Cache');
在相应控制器的类级别。
可能值得尝试 app_controller 中的帮助器声明。
我不知道你是否使用 Windows 或者更明智的系统。如果您使用的是 Linux 或 OSX 或其他操作系统,请在控制台窗口中将目录更改为
app/tmp
和chmod -R 777 。
递归地chown 可能是值得的
&chgrp
也可以更改为任何 Web 用户。删除所有缓存文件 - 将目录保留在那里。
再试一次。
Dumb checks, sorry, but just to make sure:
Capitalise the words 'javascript' and 'cache'
i.e.
var $helpers = array('Javascript','Cache');
not as you have pasted.Ensure you've added
var $cacheAction = array('main/'=>86400);
andvar $helpers = array('Javascript','Cache');
at Class level in the appropriate controller.
It might be worth trying the helper declaration in the app_controller.
I don't know if you're on Windows or something more sensible. If you're on Linux or OSX or whatever, in a console window, change directory to
app/tmp
andchmod -R 777 .
It's probably worthwhile recursivelychown
&chgrp
to whatever the web user is, too.Delete all the cache files - leave the directories there.
Try again.
这是一篇关于 cakephp 视图缓存的全新帖子,您可能想查看一下 http://nuts-and-bolts-of-cakephp.com/2011/02/05/make-your-cakephp-app -使用视图缓存速度更快/
here is a brand new post on view caching for cakephp, you might want to check it out http://nuts-and-bolts-of-cakephp.com/2011/02/05/make-your-cakephp-app-ridiculously-faster-with-view-caching/