开发者

Full view caching for dynamic routes in cakephp

I am having some issues with full view caching in cakephp.

The url that I would like to cache is /posts/badge/23/size:180x150 I have been able to cache the view successfully by adding $cacheAction = "1 hour"; to the controller.

Since I do not want to cache all methods in the controller (just specific methods) I tried to use the array syntax to match the url /posts/badge/23/size:180x150 where 23 is the post ID and size is a named parameter (there are 2 variations of size).

So my question is what is the proper (if any) match to place in cacheAction to cache all posts/badges/* Here are some examples that I have tried:

var $cacheAction = array(
        'badge/*' => '+1 hour',
        'posts/badge/23/size:180x150' => 开发者_运维百科'1 hour',
        'badge/23/size:180x150' => '1 hour',
        'posts/badge/:id/:size' => '1 hour',
        'badge/:id/:size' => '1 hour',
);

None of these seem to match (or at least do not cache for some reason). I do need to cache posts/badge//size: and trap each of the parameters being passed.

Again, if I set $cacheAction = "1 hour"; then the cache file is created (the file tmp/cache/views/posts_badge_23_size_180x150.php is created)

Has anyone been able to create a cache for a dynamic url?


CakePHP's CacheHelper currently isn't capable of Routes. CacheHelper::cache(), which is responsible for parsing and checking the $cacheAction settings does not use any Router functionality, it just does some string checking.

You can use your own CacheHelper, just modify the cache() method appropriately and place the file cache.php in app/views/helpers.

This ticket is similiar to your problem, the solution posted there may help you: trac.cakephp.org/ticket/6192


On this page: Caching in the Controller it says:

Remember to use your routes in the $cacheAction if you have any.

So try creating some routes that match your URL structure and using them for cacheAction keys. Please report back if it works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜