Class: Eld::Cache::Memory
- Inherits:
-
Object
- Object
- Eld::Cache::Memory
- Defined in:
- lib/eld/cache/memory.rb
Instance Method Summary collapse
- #clear ⇒ Object
- #fetch(&block) ⇒ Object
-
#initialize ⇒ Memory
constructor
A new instance of Memory.
- #set(&block) ⇒ Object
Constructor Details
#initialize ⇒ Memory
Returns a new instance of Memory.
6 7 8 |
# File 'lib/eld/cache/memory.rb', line 6 def initialize @storage = {} end |
Instance Method Details
#clear ⇒ Object
28 29 30 31 32 |
# File 'lib/eld/cache/memory.rb', line 28 def clear @storage = {} nil end |
#fetch(&block) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/eld/cache/memory.rb', line 10 def fetch(&block) current_time = Time.now.utc.to_i if @storage[:data] && @storage[:expires_at] > current_time @storage[:data] else set(&block) end end |
#set(&block) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/eld/cache/memory.rb', line 20 def set(&block) response = block.call @storage = response response[:data] end |