Obama Day Caching Funtime

Obama Day was caching day!

Obama Day was caching day!

Obama day was sort of intense! Not only did Aretha Franklin have a sweet hat, but all the internet traffic on CNN Live put the hurt on old skool Spongecell Promote. Chris  saved the day by quickly page caching the content that was in high demand. So basically some files were copied and everyone was happy (except maybe Texas?)

This trick is super obvi, but hella useful, yo. But, <tear>, its not a permanent fix. Alas, not every day can be Obama Day ! So I set out to fix this permanently. We need to page cache for one customer who always sends the same request, expire the page when the data changes, and action cache for everyone else who is not logged in.

So I wrote a tiny little conditional page cache plugin to let you choose your caching type at runtime. You want to page cache giraffe 1, action cache giraffe 2 when they are green and serve everything else straight up.

class PictureController

  conditionally_cache :giraffe

  def page_cache?; @giraffe == 1; end
  def action_cache?; @giraffe = 2 && @giraffe_color = 'blue'; end

  def giraffe
    @giraffe = blah_blah

To clarify the temporary caching trick:
Suppose you have: http://snowgiraffe.com/pictures/giraffe/1.html

Then you simply move the file to:


One Response to Obama Day Caching Funtime

  1. […] to some Obama day drama, I wrote a little plugin that allows you to conditionally page or action cache at runtime. This […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: