Class: Rddd::Presenters::CacheEntry
- Inherits:
-
Object
- Object
- Rddd::Presenters::CacheEntry
- Defined in:
- lib/rddd/presenters/cache_entry.rb
Overview
Cache object providing several caching methods on top of the chosen strategy.
Instance Method Summary collapse
- #delete ⇒ Object
-
#initialize(key, strategy) ⇒ CacheEntry
constructor
A new instance of CacheEntry.
- #read ⇒ Object
- #write(data, timeout = nil) ⇒ Object
Constructor Details
#initialize(key, strategy) ⇒ CacheEntry
Returns a new instance of CacheEntry.
8 9 10 11 |
# File 'lib/rddd/presenters/cache_entry.rb', line 8 def initialize(key, strategy) @key = key @strategy = strategy end |
Instance Method Details
#delete ⇒ Object
13 14 15 |
# File 'lib/rddd/presenters/cache_entry.rb', line 13 def delete write(nil) end |
#read ⇒ Object
17 18 19 |
# File 'lib/rddd/presenters/cache_entry.rb', line 17 def read @strategy.get(@key) end |
#write(data, timeout = nil) ⇒ Object
21 22 23 24 25 |
# File 'lib/rddd/presenters/cache_entry.rb', line 21 def write(data, timeout = nil) expire_at = timeout ? Time.now + timeout : nil @strategy.set(@key, data, expire_at) end |