Class: Rddd::Presenters::CacheEntry

Inherits:
Object
  • Object
show all
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

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

#deleteObject



13
14
15
# File 'lib/rddd/presenters/cache_entry.rb', line 13

def delete
  write(nil)
end

#readObject



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