scoped_cache_key / expire_scoped_cache_key for caching & sweeping of model-related caches
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.travis.yml
Gemfile
Gemfile.lock
Rakefile
Readme.md
scoped_cache_keys.gemspec

Readme.md

Add scoped_cache_key / expire_scoped_cache_key to your models for caching/sweeping of model-related caches.

Install

sudo gem install scoped_cache_keys

Or

rails plugin install git://github.com/grosser/scoped_cache_keys.git

Usage

Gives you a key that will change whenever expire_scoped_cache_key is called.

<% cache user.scoped_cache_key :products do %>
  ... user.products.each ...
<% end %>

<% cache "something-else-" + user.scoped_cache_key :products %>
  ... will also be expired ...
<% end %>

# app/sweepers/product_sweeper.rb
class ProductSweeper < ActionController::Caching::Sweeper
  observe Product

  def after_save(record)
    record.user.expire_scoped_cache_key :products
  end
end

Author

Zendesk
michael@grosser.it
License: MIT
Build Status