Class: Caching::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/caching/storage.rb

Instance Method Summary collapse

Constructor Details

#initializeStorage

Returns a new instance of Storage.



4
5
6
# File 'lib/caching/storage.rb', line 4

def initialize
  @storage = {}
end

Instance Method Details

#clear(*keys) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/caching/storage.rb', line 20

def clear(*keys)
  if keys.empty?
    @storage = {}
  else
    keys.each { |k| @storage.delete k }
  end
end

#fetch(key) ⇒ Object



16
17
18
# File 'lib/caching/storage.rb', line 16

def fetch(key)
  read(key) || write(key, yield)
end

#read(key) ⇒ Object



8
9
10
# File 'lib/caching/storage.rb', line 8

def read(key)
  @storage[key]
end

#write(key, value) ⇒ Object



12
13
14
# File 'lib/caching/storage.rb', line 12

def write(key, value)
  @storage[key] = value
end