Class: MiniMemoryStore
- Inherits:
-
Object
- Object
- MiniMemoryStore
- Defined in:
- lib/mini_memory_store.rb,
lib/mini_memory_store/version.rb
Constant Summary collapse
- VERSION =
"1.0.0"
Instance Method Summary collapse
- #cache ⇒ Object
- #clear ⇒ Object
- #get ⇒ Object
-
#initialize(expires_in:) ⇒ MiniMemoryStore
constructor
A new instance of MiniMemoryStore.
- #set(value) ⇒ Object
Constructor Details
#initialize(expires_in:) ⇒ MiniMemoryStore
Returns a new instance of MiniMemoryStore.
3 4 5 6 |
# File 'lib/mini_memory_store.rb', line 3 def initialize(expires_in:) @expires_in = expires_in @last_set = 0 end |
Instance Method Details
#cache ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/mini_memory_store.rb', line 21 def cache value = get if value.nil? value = yield set value end value end |
#clear ⇒ Object
30 31 32 |
# File 'lib/mini_memory_store.rb', line 30 def clear set nil end |
#get ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/mini_memory_store.rb', line 13 def get if expired? nil else @value end end |
#set(value) ⇒ Object
8 9 10 11 |
# File 'lib/mini_memory_store.rb', line 8 def set(value) @last_set = now @value = value end |