class ActiveSupport::Cache::PrefixedStore
Public: A wrapper around an ActiveSupport::Cache
to prefix all keys.
Example
cache = ActiveSupport::Cache::PrefixedStore.new 'namespace:', Rails.cache
Attributes
prefix[R]
store[R]
Public Class Methods
new(prefix, store)
click to toggle source
# File lib/active_support/cache/prefixed_store.rb, line 12 def initialize(prefix, store) @prefix = prefix @store = store end
Public Instance Methods
clear()
click to toggle source
# File lib/active_support/cache/prefixed_store.rb, line 36 def clear store.delete_matched(prefix) end
fetch(key, *args, &block)
click to toggle source
# File lib/active_support/cache/prefixed_store.rb, line 32 def fetch(key, *args, &block) store.fetch(prefixed(key), *args, &block) end
read(key, *args, &block)
click to toggle source
# File lib/active_support/cache/prefixed_store.rb, line 17 def read(key, *args, &block) store.read(prefixed(key), *args, &block) end
read_multi(*keys)
click to toggle source
# File lib/active_support/cache/prefixed_store.rb, line 21 def read_multi(*keys) k = keys.map { |key| prefixed(key) } store.read_multi(*k).each_with_object(Hash.new) do |t,memo| memo[t[0].sub(prefix, '')] = t[1] end end
write(key, *args, &block)
click to toggle source
# File lib/active_support/cache/prefixed_store.rb, line 28 def write(key, *args, &block) store.write(prefixed(key), *args, &block) end
Private Instance Methods
prefixed(key)
click to toggle source
# File lib/active_support/cache/prefixed_store.rb, line 42 def prefixed(key) "#{prefix}#{key}" end