Class: Makara::Cache::MemoryStore

Inherits:
Object
  • Object
show all
Defined in:
lib/makara/cache/memory_store.rb

Instance Method Summary collapse

Constructor Details

#initializeMemoryStore

Returns a new instance of MemoryStore.



5
6
7
# File 'lib/makara/cache/memory_store.rb', line 5

def initialize
  @data = {}
end

Instance Method Details

#read(key) ⇒ Object



9
10
11
12
# File 'lib/makara/cache/memory_store.rb', line 9

def read(key)
  clean
  @data[key].try(:[], 0)
end

#write(key, value, options = {}) ⇒ Object



14
15
16
17
18
# File 'lib/makara/cache/memory_store.rb', line 14

def write(key, value, options = {})
  clean
  @data[key] = [value, Time.now.to_i + (options[:expires_in] || 5).to_i]
  true
end