Class: Jouba::Cache::Memory

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/jouba/cache.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMemory

Returns a new instance of Memory.



22
23
24
# File 'lib/jouba/cache.rb', line 22

def initialize
  @store = MemoryStore.new
end

Instance Attribute Details

#storeObject (readonly)

Returns the value of attribute store.



18
19
20
# File 'lib/jouba/cache.rb', line 18

def store
  @store
end

Class Method Details

.load(file_path) ⇒ Object



35
36
37
# File 'lib/jouba/cache.rb', line 35

def self.load(file_path)
  @store = MemoryStore.load(file_path)
end

Instance Method Details

#fetch(key) ⇒ Object



26
27
28
# File 'lib/jouba/cache.rb', line 26

def fetch(key)
  get(key) || yield.tap { |value| store.set(key, value) }
end

#refresh(key, value) ⇒ Object



30
31
32
33
# File 'lib/jouba/cache.rb', line 30

def refresh(key, value)
  store.set(key, value)
  yield
end