views:

736

answers:

2

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?

A: 

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.

Marko
There is no special routing being done here. It is following the default route. I am pretty certian that what they are talking about here is if you have changed the default route (say renamed view to show) then you would want the cacheAction to match the routes in your route.php
Ryan
+2  A: 

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

rscherer