views:

87

answers:

1

I have a landing page on rails with "blog" style posts. Since it's the most visited page on the site, I'm using action caching. The cache is cleared upon a change of the model.

However, when adding new blog posts, i'd like to be able to create posts in the --future-- (a la queueing posts in Tumblr).

So simply observing the model won't work anymore for clearing the cache.

Is there any better way of clearing the cache correctly other than running the job periodically (every half hour) ?

A: 

You can use an expirable cache. If your cache backend is Memcached, this feature is supported by default. Otherwise, you need to create a cache key including a value that expires the cache after a defined amount of time.

Or you can also follow an other way. Instead of publishing records where publised_at < Time.now (I'm assuming your current behavior falls into this case), you can run a cron and update a status database field. In this way the update will trigger your sweeper and clear the cache.

The first solution is actually the best one.

Simone Carletti