CakePHP
CakePHP cache workarounds (part 1)
I've been messing around with CakePHP's view caching recently and hit a couple bugs. They've both been posted in the tracker, but remain unfixed at the moment.
The first issue occurs when you try to cache the main page of your site - whatever appears when you go to www.site.com. This was broke in changeset 4269. Before this change the default page would get saved in the cache folder as ".php". Not an ideal file name, but at least it worked. With the addition of this change the method returns without writing the cache file.
Someone suggested a fix for this in the CakePHP Google groups, but the solution only partially works. Firstly putting the two ReWrite rules in .htaccess above the generic CakePHP rule screws up the loading of css files - I don't understand exactly why. Moving the two rules to the bottom does allow for the page to be loaded w/ css and the cached view is written to the disk.
HOWEVER, the cached view is never used and will just be re-written on every page hit. This is because the code that determines the cached file name is different when reading the file then when writing the file. The reading code uses a function called setUri. The return for this function is dependent on the server setup, but in my case it returns "/", which doesn't match the cache file written after using the ReWrite suggested above.
THE SOLUTION: You have to actually redirect the browser to the correct page so that address changes. To do that put this rule in your .htaccess AT THE BOTTOM.
RewriteRule ^$ /controller/action [R,L]
RewriteRule ^/$ /controller/action [R,L]
This does generate an extra request due to the redirect. The optimal solution is to fix this in the CakePHP core. Once I have a better understanding of the cache code I may suggest a fix, assuming someone doesn't beat me to it.
CakePHP Session Helper Bug?
According to everything I've read I should be able to wrap the CakePHP session helper in nocache tags and have dynamic areas on cached pages. But this doesn't work at all.
Digging through the code I don't see how this could possible work. The session helper doesn't start the session, only the session component does. But with cached views the session component is never called - that's the point of caching - avoiding all the component overhead.
I tried posting a message in the CakePHP Google Groups, but no response yet. And the IRC site is mysteriously down.
For now I can work around by either switching the helper to start the session or by instantiating an instance of CakeSession in my view. I don't really like either of these solutions and I may post a bug report if I don't get a response from the groups and the IRC doesn't come back.
