September 11, 2006

Posted by John

Tagged plugin

Older: Rails 1.2 Features

Newer: Memcaching Rails

Simple Caching

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
  • 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.

I also wrote a bit about it on my personal blog.


Thoughts? Do Tell...

textile enabled, preview above, please be nice
use <pre><code class="ruby"></code></pre> for code blocks


Authored by John Nunemaker (Noo-neh-maker), a programmer who has fallen deeply in love with Ruby. Learn More.


Release your software more often with fewer problems.
Flip your features.