Module: TypedCache::Backend
- Defined in:
- lib/typed_cache/backend.rb
Overview
Marker mixin for concrete cache back-ends. A Backend is a Store, but the reverse is not necessarily true (decorators also include Store). By tagging back-ends with this module we can type-check and register them separately from decorators.
Back-ends should not assume they wrap another store – they are the leaf nodes that actually persist data.
Instance Method Summary collapse
- #clear(**opts) ⇒ Object
- #delete(key, **opts) ⇒ Object
- #fetch(key, **opts, &block) ⇒ Object
- #fetch_multi(keys, **opts, &block) ⇒ Object
- #key?(key) ⇒ Boolean
- #read(key, **opts) ⇒ Object
- #read_multi(keys, **opts) ⇒ Object
- #write(key, value, **opts) ⇒ Object
- #write_multi(values, **opts) ⇒ Object
Instance Method Details
#clear(**opts) ⇒ Object
68 69 70 |
# File 'lib/typed_cache/backend.rb', line 68 def clear(**opts) raise NotImplementedError, "#{self.class} must implement #clear" end |
#delete(key, **opts) ⇒ Object
56 57 58 |
# File 'lib/typed_cache/backend.rb', line 56 def delete(key, **opts) raise NotImplementedError, "#{self.class} must implement #delete" end |
#fetch(key, **opts, &block) ⇒ Object
74 75 76 |
# File 'lib/typed_cache/backend.rb', line 74 def fetch(key, **opts, &block) raise NotImplementedError, "#{self.class} must implement #fetch" end |
#fetch_multi(keys, **opts, &block) ⇒ Object
80 81 82 |
# File 'lib/typed_cache/backend.rb', line 80 def fetch_multi(keys, **opts, &block) keys.to_h { |key| [key, fetch(key, **opts, &block)] } end |
#key?(key) ⇒ Boolean
62 63 64 |
# File 'lib/typed_cache/backend.rb', line 62 def key?(key) raise NotImplementedError, "#{self.class} must implement #key?" end |
#read(key, **opts) ⇒ Object
32 33 34 |
# File 'lib/typed_cache/backend.rb', line 32 def read(key, **opts) raise NotImplementedError, "#{self.class} must implement #read" end |
#read_multi(keys, **opts) ⇒ Object
38 39 40 |
# File 'lib/typed_cache/backend.rb', line 38 def read_multi(keys, **opts) keys.to_h { |key| [key, read(key, **opts)] } end |
#write(key, value, **opts) ⇒ Object
44 45 46 |
# File 'lib/typed_cache/backend.rb', line 44 def write(key, value, **opts) raise NotImplementedError, "#{self.class} must implement #write" end |
#write_multi(values, **opts) ⇒ Object
50 51 52 |
# File 'lib/typed_cache/backend.rb', line 50 def write_multi(values, **opts) values.transform_values { |value| write(value, **opts) } end |