Class: Feedx::Cache::Value
- Inherits:
-
Object
- Object
- Feedx::Cache::Value
- Defined in:
- lib/feedx/cache/value.rb
Overview
A single value inside a cache.
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
-
#fetch(**opts, &block) ⇒ Object
Fetches data.
-
#initialize(cache, key) ⇒ Value
constructor
A new instance of Value.
-
#read(**opts) ⇒ Object
Read the key.
-
#write(value, **opts) ⇒ Object
Write a value.
Constructor Details
#initialize(cache, key) ⇒ Value
Returns a new instance of Value.
5 6 7 8 |
# File 'lib/feedx/cache/value.rb', line 5 def initialize(cache, key) @cache = cache @key = key end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
3 4 5 |
# File 'lib/feedx/cache/value.rb', line 3 def key @key end |
Instance Method Details
#fetch(**opts, &block) ⇒ Object
Fetches data. The optional block will be evaluated and the result stored in the cache under the key in the event of a cache miss.
22 23 24 |
# File 'lib/feedx/cache/value.rb', line 22 def fetch(**opts, &block) @cache.fetch(@key, **opts, &block) end |
#read(**opts) ⇒ Object
Read the key.
11 12 13 |
# File 'lib/feedx/cache/value.rb', line 11 def read(**opts) @cache.read(@key, **opts) end |
#write(value, **opts) ⇒ Object
Write a value.
16 17 18 |
# File 'lib/feedx/cache/value.rb', line 16 def write(value, **opts) @cache.write(@key, value, **opts) end |