timed_fragment_cache on Rails 2.1

posted in: cache, fragment caching, rails, ruby | 0

With Rails 2.1 cache_erb_fragment has been replaced by write_fragment. This breaks a plugin I really enjoy to use: timed_fragment_cache by Richard Livsey.

It basically allows you to specify an expiry for the fragments you cache, e.g. inside memcache, by adding a “meta” fragment for the fragment you store containing the expiry time.

Some usage examples – pretty self-explaining:

In your view:

<%- cache 'my_key', 1.hour.from_now do -%>
<%- end -%>

With extensive queries – your view …:

<%- cache 'some_posts' -%>