Skip to content

andreijs/activesupport-cascadestore

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ActiveSupport::Cache::CascadeStore

Hopefully this cache store is merged upstream into core with this pull request. In the meantime, packaging this up as a gem for easy access.

A thread-safe cache store implementation that cascades operations to a list of other cache stores. It is used to provide fallback cache stores when primary stores become unavailable, or to put lower latency stores in front of other cache stores.

For example, to initialize a CascadeStore that cascades through MemCacheStore, MemoryStore, and FileStore:

ActiveSupport::Cache.lookup_store(:cascade_store,
  :stores => [
    :mem_cache_store,
    :memory_store,
    :file_store
  ]
})

Cache operation behavior:

Read: returns first cache hit from :stores, nil if none found

Write/Delete: write/delete through to each cache store in :stores

Increment/Decrement: increment/decrement each store, returning the new number if any stores was successfully incremented/decremented, nil otherwise

For more background info, check out this blog post: Writing a Custom Rails Cache Store

Rails Configuration

Add to your Gemfile:

gem 'activesupport-cascadestore'

In your production.rb:

# configure with stores you want to use.
config.cache_store = [:cascade_store, :stores => [
  :memory_store,
  :file_store
]]

Development

To run tests

ruby -Itest test/caching_test.rb

License

Same license as Rails

About

write through ActiveSupport cache implementation

Resources

Stars

Watchers

Forks

Packages

No packages published