简体   繁体   English

不要在CakePHP视图中缓存动态内容

[英]Do not cache dynamic content in CakePHP views

I'm trying to cache the views with the Cache helper. 我正在尝试使用“缓存帮助器”缓存视图。 It works well for static content or for session content using <!--nocache-->{...}<!--/nocache--> but it's not working for internal action variables. 它适用于静态内容或使用<!--nocache-->{...}<!--/nocache-->会话内容,但不适用于内部操作变量。

For exemple, if I have a cachable article and an not cachable user defined rating for this article, I can't use <!--nocache-->echo $rating;<!--/nocache--> to display this rating, because the rating variable will also be cached. 例如,如果我有一篇可发表的文章,而这篇文章没有用户定义的评分,则不能使用<!--nocache-->echo $rating;<!--/nocache-->来显示此评分,因为rating变量也将被缓存。

If I understand correctly, this is intended behaviour. 如果我理解正确,这是预期的行为。

Once an action is cached, all of the view variables are serialized and the action is not called again (until the cache is cleared etc). 缓存动作后,所有视图变量都将被序列化,并且不会再次调用该动作(直到清除缓存等)。

Either: don't use view-caching, or set the cache time to expire more frequently. 要么:不使用视图缓存,要么将缓存时间设置为更频繁地过期。

If you want the rating to increase in "real time", then have your app clear the cache every time someone modifies the rating. 如果您希望评级实时提高,那么每次有人修改评级时,都要让您的应用清除缓存。

Your app will benefit from a cached version at least some of the time. 您的应用程序至少在某些时候会从缓存版本中受益。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM