Class: ActiveSupport::Cache::PrefixedStore
- Inherits:
-
Object
- Object
- ActiveSupport::Cache::PrefixedStore
- Defined in:
- lib/active_support/cache/prefixed_store.rb
Overview
Public: A wrapper around an ActiveSupport::Cache to prefix all keys.
Example
cache = ActiveSupport::Cache::PrefixedStore.new 'namespace:', Rails.cache
Instance Attribute Summary collapse
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
- #clear ⇒ Object
- #fetch(key, *args, &block) ⇒ Object
-
#initialize(prefix, store) ⇒ PrefixedStore
constructor
A new instance of PrefixedStore.
- #read(key, *args, &block) ⇒ Object
- #read_multi(*keys) ⇒ Object
- #write(key, *args, &block) ⇒ Object
Constructor Details
#initialize(prefix, store) ⇒ PrefixedStore
Returns a new instance of PrefixedStore.
12 13 14 15 |
# File 'lib/active_support/cache/prefixed_store.rb', line 12 def initialize(prefix, store) @prefix = prefix @store = store end |
Instance Attribute Details
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
10 11 12 |
# File 'lib/active_support/cache/prefixed_store.rb', line 10 def prefix @prefix end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
10 11 12 |
# File 'lib/active_support/cache/prefixed_store.rb', line 10 def store @store end |
Instance Method Details
#clear ⇒ Object
36 37 38 |
# File 'lib/active_support/cache/prefixed_store.rb', line 36 def clear store.delete_matched(prefix) end |
#fetch(key, *args, &block) ⇒ Object
32 33 34 |
# 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) ⇒ Object
17 18 19 |
# 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) ⇒ Object
21 22 23 24 25 26 |
# 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) ⇒ Object
28 29 30 |
# File 'lib/active_support/cache/prefixed_store.rb', line 28 def write(key, *args, &block) store.write(prefixed(key), *args, &block) end |