Class: RateLimit::ToyCache

Inherits:
Object
  • Object
show all
Defined in:
lib/ratelimit/toy_cache.rb

Constant Summary collapse

@@cache =
{}

Instance Method Summary collapse

Instance Method Details

#fetch(name, opts, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/ratelimit/toy_cache.rb', line 7

def fetch(name, opts, &block)
  result = read(name)

  return result unless result.nil?

  r = yield

  write(name, r)
  read(name)
end

#read(name) ⇒ Object



22
23
24
# File 'lib/ratelimit/toy_cache.rb', line 22

def read(name)
  @@cache[name]
end

#write(name, value, opts = nil) ⇒ Object



18
19
20
# File 'lib/ratelimit/toy_cache.rb', line 18

def write(name, value, opts=nil)
  @@cache[name] = value
end