Skip to content

baozoumanhua/scope_cache_key

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scope Cache Key

This gem adds the cache_key functionality to ActiveRecord scopes.

This is useful when caching a page that contains multiple records. It is now possible to cache the entire page based on a scope. If any record in the scope changes, the entire cache will be busted.

This should likely be used in a Russian Doll Caching scenario.

NOTE: This currently only works with Postgresql. Adding support for MySQL should be trivial.

Build Status

Installation

Add this line to your application's Gemfile:

gem 'scope_cache_key'

Usage

Example:

<%
scope = Article.page(1) # This should probably be done in your controller!
cache scope do
  # logic to render and cache each article here
end
%>

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

About

Add cache_key functionality to ActiveRecord scopes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%