Class: Cache

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

Instance Method Summary collapse

Constructor Details

#initialize(instance, method) ⇒ Cache

Returns a new instance of Cache.



3
4
5
6
7
# File 'lib/paymo/cache.rb', line 3

def initialize(instance, method)
  @data     = {}
  @instance = instance
  @method   = method
end

Instance Method Details

#get(key) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/paymo/cache.rb', line 9

def get(key)
  begin
    @data.fetch(key)
  rescue KeyError
    set(key)
    get(key)
  end
end

#set(key) ⇒ Object



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

def set(key)
  @data.store key, value(key)
end