Created
July 22, 2014 14:38
-
-
Save edjames/03d13a0f45987e0cf4a5 to your computer and use it in GitHub Desktop.
Multi-namespace cache handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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