Reduce cache requests by preheating via multi_get
Ruby
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
Gemfile
Gemfile.lock
Rakefile
Readme.md
VERSION
init.rb
preheatable_cache.gemspec

Readme.md

Reduce cache requests by preheating via multi_get.

Makes Rails MemCacheStore preheatable via read_multi, for keys that will later be used.
Clears the preheated cache after each request.

  • not threadsave
  • not altered when writing/incrementing/... underlying cache store

Install

gem install preheatable_cache

OR script/plugin install http://github.com/grosser/preheatable_cache

Usage

# controller - multi_get to fetch all keys at once
Rails.cache.preheat @products.map{|p| "views/product_#{p.id}" }

# view - no requests to the cache server
<% cache "product_#{product.id}" do %>
  ...
<% end %>

Author

Michael Grosser
grosser.michael@gmail.com
Hereby placed under public domain, do what you want, just do not hold me accountable...