In Rails, caching is one of those things that is made pretty easy, but can also be difficult when you want to do complex tasks with the caching -- such as expiring it. There are two ways with expire_fragment within the logic of your controllers or using an Observers.
This plugin allows caching to be expired on predefined time limit. The idea is that the caching takes cared of the expiration instead of writing conditions in the controller. I understand that it goes against the idea of why the caching mechanism does not have them now.
To the plugin. Its an extension of cache method that has logic for the time limit. The method to use within views is called cache_timeout. The first argument of the method is the regular Hash/String of the cache key and the second argument is the timeout value (being a Time class value).
# This is last 5 minutes of posts from our forums:
<% for post in @posts %>
<%=post.title%> - by <%=post.author.username%> at <%=post.created_at>Unknown end tag for
To enforce the timeout cache value within the controller don't use the read_fragment method -- unless really needed. The method that is provided to check that the timeout value has is expired is is_cache_expired?. The method takes the argument of the cache key.
Example Usage within controller:
@posts = Post.find(:all)
These details are provided for information only. No information here is legal advice and should not be used as such.