Taggable cache

This gem simplifies cache expiration in rails by adding depends_on helper, which expires cache element when depending object is changed/deleted.

How to use

Controller(action caching):

caches_action :index

def index
  Page.load_lot_of_data

  #this depends on any Page object change - creation, deletion, change
  depends_on Page
end

View(fragment caching):

<%# Page.active can be AR scope, every Page object on change is checked if it is in this scope, and if is - expires cache element %>
<% cache 'cache_entry', :depends_on => [Page.active] do %>
  <% Page.load_lot_of_data %>
<% end %>

Usage with Rails.cache:

page = Page.first
#this cache key expires only if this Page object is changed/deleted
Rails.cache.write('key', 'value', :depends_on => [page])

Usage with cells gem:

class TabsCell < Cell::Rails
  cache :index, nil, :depends_on => [Category, Metacategory, Product]

  def index
    render
  end
end

Build Status <img src=“https://secure.travis-ci.org/brain-geek/taggable-cache.png”/>

Contributing to taggable-cache

  • Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet.

  • Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it.

  • Fork the project.

  • Commit and push until you are happy with your contribution.

  • Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright © 2012 Alex Rozumey. See LICENSE.txt for further details.