Class: ActiveSupport::Cache::NamespacedStore
- Inherits:
-
Object
- Object
- ActiveSupport::Cache::NamespacedStore
- Defined in:
- lib/active_support/cache/namespaced_store.rb
Overview
Public: A wrapper around an ActiveSupport::Cache to prefix all keys.
Example
cache = ActiveSupport::Cache::NamespacedStore.new 'namespace:', Rails.cache
Instance Attribute Summary collapse
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
- #clear ⇒ Object
- #fetch(key, *args, &block) ⇒ Object
-
#initialize(namespace, store) ⇒ NamespacedStore
constructor
A new instance of NamespacedStore.
- #read(key, *args, &block) ⇒ Object
- #read_multi(*keys) ⇒ Object
- #write(key, *args, &block) ⇒ Object
Constructor Details
#initialize(namespace, store) ⇒ NamespacedStore
Returns a new instance of NamespacedStore.
12 13 14 15 |
# File 'lib/active_support/cache/namespaced_store.rb', line 12 def initialize(namespace, store) @namespace = namespace @store = store end |
Instance Attribute Details
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
10 11 12 |
# File 'lib/active_support/cache/namespaced_store.rb', line 10 def namespace @namespace end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
10 11 12 |
# File 'lib/active_support/cache/namespaced_store.rb', line 10 def store @store end |
Instance Method Details
#clear ⇒ Object
36 37 38 |
# File 'lib/active_support/cache/namespaced_store.rb', line 36 def clear store.delete_matched(namespace) end |
#fetch(key, *args, &block) ⇒ Object
32 33 34 |
# File 'lib/active_support/cache/namespaced_store.rb', line 32 def fetch(key, *args, &block) store.fetch(namespaced(key), *args, &block) end |
#read(key, *args, &block) ⇒ Object
17 18 19 |
# File 'lib/active_support/cache/namespaced_store.rb', line 17 def read(key, *args, &block) store.read(namespaced(key), *args, &block) end |
#read_multi(*keys) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/active_support/cache/namespaced_store.rb', line 21 def read_multi(*keys) k = keys.map { |key| namespaced(key) } store.read_multi(*k).each_with_object(Hash.new) do |t,memo| memo[t[0].sub(namespace, '')] = t[1] end end |
#write(key, *args, &block) ⇒ Object
28 29 30 |
# File 'lib/active_support/cache/namespaced_store.rb', line 28 def write(key, *args, &block) store.write(namespaced(key), *args, &block) end |