Recently on a project for the Notre Dame Web Group, I had to implement caching. I read several articles and even looked at Mephisto’s caching system to determine what would be the best method. I liked how Mephisto referenced the models being used on a cached page but decided that the forum website did not need something that sophisticated.
I thought page caching looked pretty cool and decided that all I really needed was something that would blow away all those cached files in the public folder each time certain model records were modified. I created a simple plugin which makes doing just that really easy.
How To Use
- Install the plugin (
script/plugin install http://svn.addictedtonew.com/plugins/addicted_to_caching/)
- Use page caching as described in the api
- Add acts_as_cache_clearer to any model that you would like to clear the cache upon having one of its records modified (saved or destroyed)
How It Works
Because page caching uses the public folder to store it’s cached files, all that is need to clear the entire cache is to remove each entry (file or folder) in the public folder that is not suppose to exist. The plugin contains a PROTECTED_ENTRIES array which determines which entries are not to be deleted in the public folder.