Class: Feedx::Cache::Abstract
- Inherits:
-
Object
- Object
- Feedx::Cache::Abstract
- Defined in:
- lib/feedx/cache/abstract.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#clear ⇒ Object
Clears cache.
-
#fetch(key, **opts) ⇒ Object
Fetches data from the cache, using the given key.
-
#read(_key) ⇒ Object
Read reads a key.
-
#value(key) ⇒ Feedx::Abstract::Value
Returns a wrapper around a single value.
-
#write(_key, _value) ⇒ Object
Write writes a key/value pair.
Instance Method Details
#clear ⇒ Object
Clears cache.
3 4 5 |
# File 'lib/feedx/cache/abstract.rb', line 3 def clear raise 'Not implemented' end |
#fetch(key, **opts) ⇒ Object
Fetches data from the cache, using the given key. The optional block will be evaluated and the result stored in the cache in the event of a cache miss.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/feedx/cache/abstract.rb', line 20 def fetch(key, **opts) value = read(key, **opts) if block_given? value ||= yield write(key, value, **opts) if value end value end |
#read(_key) ⇒ Object
Read reads a key.
8 9 10 |
# File 'lib/feedx/cache/abstract.rb', line 8 def read(_key, **) raise 'Not implemented' end |
#value(key) ⇒ Feedx::Abstract::Value
Returns a wrapper around a single value.
32 33 34 |
# File 'lib/feedx/cache/abstract.rb', line 32 def value(key) Feedx::Cache::Value.new(self, key) end |
#write(_key, _value) ⇒ Object
Write writes a key/value pair.
13 14 15 |
# File 'lib/feedx/cache/abstract.rb', line 13 def write(_key, _value, **) raise 'Not implemented' end |