0.02
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Add cache_key functionality to scopes
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.2.12
~> 3.2.12
~> 1.1.2
>= 0
>= 0
~> 2.13.0

Runtime

>= 3.2.9
 Project Readme

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