Class: Redis

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

Instance Method Summary collapse

Instance Method Details

#cache(key, expire = nil) ⇒ Object



2
3
4
5
6
7
8
9
10
11
# File 'lib/ievkit/cache.rb', line 2

def cache(key, expire = nil)
  value = get(key)
  return JSON.parse(value) if value
  return nil unless block_given?
  value = yield(self)
  return nil unless value
  set(key, value.to_json)
  expire(key, expire) if expire.to_i > 0
  value
end