Skip to content

Instantly share code, notes, and snippets.

@edjames
Created July 22, 2014 14:38
Show Gist options
  • Save edjames/03d13a0f45987e0cf4a5 to your computer and use it in GitHub Desktop.
Save edjames/03d13a0f45987e0cf4a5 to your computer and use it in GitHub Desktop.
Multi-namespace cache handler
class MultiCache
include Singleton
attr_reader :rails_cache, :custom_cache
def initialize
@rails_cache = Rails.cache
@custom_cache = ActiveSupport::Cache::MemCacheStore.new(
'your-cache-ip-address', :namespace => 'rails4-namespace')
end
def self.delete(key)
instance.delete(key)
end
# this will allow our MemoryCache to be called just like Rails.cache
# every method passed to it will be passed to our MemoryStore
def method_missing(m, *args, &block)
rails_cache.send(m, *args, &block)
custom_cache.send(m, *args, &block)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment