简体   繁体   中英

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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