Class: TypedCache::Backends::ActiveSupport
- Inherits:
-
Object
- Object
- TypedCache::Backends::ActiveSupport
- Includes:
- TypedCache::Backend
- Defined in:
- lib/typed_cache/backends/active_support.rb
Overview
Adapter that wraps any ActiveSupport::Cache::Store to work with TypedCache
Instance Attribute Summary collapse
-
#cache_store ⇒ Object
readonly
: ::ActiveSupport::Cache::Store.
-
#default_options ⇒ Object
readonly
: Hash[Symbol, top].
Instance Method Summary collapse
-
#clear ⇒ Object
: -> void.
-
#delete(key) ⇒ Object
: (cache_key) -> V?.
-
#fetch(key, **kwargs, &block) ⇒ Object
: (cache_key, **top) { () -> V? } -> V?.
-
#fetch_all(keys, **kwargs, &block) ⇒ Object
: (Array, **top) { (CacheKey) -> V? } -> Hash[cache_key, V].
-
#initialize(cache_store, default_options = {}) ⇒ ActiveSupport
constructor
: (::ActiveSupport::Cache::Store, ?Hash[Symbol, top]) -> void.
-
#key?(key) ⇒ Boolean
: (cache_key) -> bool.
-
#raw_cache ⇒ Object
: -> ::ActiveSupport::Cache::Store.
-
#read(key, **kwargs) ⇒ Object
: (cache_key, **top) -> V?.
-
#read_all(keys, **kwargs) ⇒ Object
: (Array, **top) -> Hash[cache_key, V].
-
#with_options(new_options) ⇒ Object
: (Hash[Symbol, top]) -> ActiveSupport.
-
#write(key, value, **kwargs) ⇒ Object
: (cache_key, V, **top) -> V.
-
#write_all(values, **kwargs) ⇒ Object
: (Hash[cache_key, V], **top) -> Array.
Methods included from TypedCache::Backend
#fetch_multi, #read_multi, #write_multi
Constructor Details
#initialize(cache_store, default_options = {}) ⇒ ActiveSupport
: (::ActiveSupport::Cache::Store, ?Hash[Symbol, top]) -> void
14 15 16 17 |
# File 'lib/typed_cache/backends/active_support.rb', line 14 def initialize(cache_store, = {}) @cache_store = cache_store @default_options = end |
Instance Attribute Details
#cache_store ⇒ Object (readonly)
: ::ActiveSupport::Cache::Store
10 11 12 |
# File 'lib/typed_cache/backends/active_support.rb', line 10 def cache_store @cache_store end |
#default_options ⇒ Object (readonly)
: Hash[Symbol, top]
11 12 13 |
# File 'lib/typed_cache/backends/active_support.rb', line 11 def @default_options end |
Instance Method Details
#clear ⇒ Object
: -> void
69 70 71 |
# File 'lib/typed_cache/backends/active_support.rb', line 69 def clear cache_store.clear() end |
#delete(key) ⇒ Object
: (cache_key) -> V?
39 40 41 |
# File 'lib/typed_cache/backends/active_support.rb', line 39 def delete(key) cache_store.delete(key, ) end |
#fetch(key, **kwargs, &block) ⇒ Object
: (cache_key, **top) { () -> V? } -> V?
51 52 53 |
# File 'lib/typed_cache/backends/active_support.rb', line 51 def fetch(key, **kwargs, &block) cache_store.fetch(key, .merge(kwargs), &block) end |
#fetch_all(keys, **kwargs, &block) ⇒ Object
: (Array, **top) { (CacheKey) -> V? } -> Hash[cache_key, V]
57 58 59 |
# File 'lib/typed_cache/backends/active_support.rb', line 57 def fetch_all(keys, **kwargs, &block) cache_store.fetch_multi(*keys, .merge(kwargs), &block) end |
#key?(key) ⇒ Boolean
: (cache_key) -> bool
63 64 65 |
# File 'lib/typed_cache/backends/active_support.rb', line 63 def key?(key) cache_store.exist?(key, ) end |
#raw_cache ⇒ Object
: -> ::ActiveSupport::Cache::Store
79 80 81 |
# File 'lib/typed_cache/backends/active_support.rb', line 79 def raw_cache cache_store end |
#read(key, **kwargs) ⇒ Object
: (cache_key, **top) -> V?
21 22 23 |
# File 'lib/typed_cache/backends/active_support.rb', line 21 def read(key, **kwargs) cache_store.read(key, .merge(kwargs)) end |
#read_all(keys, **kwargs) ⇒ Object
: (Array, **top) -> Hash[cache_key, V]
45 46 47 |
# File 'lib/typed_cache/backends/active_support.rb', line 45 def read_all(keys, **kwargs) cache_store.read_multi(*keys, .merge(kwargs)) end |
#with_options(new_options) ⇒ Object
: (Hash[Symbol, top]) -> ActiveSupport
74 75 76 |
# File 'lib/typed_cache/backends/active_support.rb', line 74 def () self.class.new(cache_store, ) end |
#write(key, value, **kwargs) ⇒ Object
: (cache_key, V, **top) -> V
27 28 29 |
# File 'lib/typed_cache/backends/active_support.rb', line 27 def write(key, value, **kwargs) cache_store.write(key, value, .merge(kwargs)) end |
#write_all(values, **kwargs) ⇒ Object
: (Hash[cache_key, V], **top) -> Array
33 34 35 |
# File 'lib/typed_cache/backends/active_support.rb', line 33 def write_all(values, **kwargs) cache_store.write_multi(values, .merge(kwargs)) end |