kirlev / activesupport-cascadestore

write through ActiveSupport cache implementation

Home Page:https://github.com/jch/activesupport-cascadestore

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

https://github.com/jch/activesupport-cascadestore


Languages

Language:Ruby 85.3%Language:HTML 8.7%Language:CSS 2.7%Language:JavaScript 2.4%Language:CoffeeScript 0.9%