Module: FastCache::Evaluator

Defined in:
lib/fastcache/interface/evaluator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_expirationObject

Returns the value of attribute default_expiration.



4
5
6
# File 'lib/fastcache/interface/evaluator.rb', line 4

def default_expiration
  @default_expiration
end

#evaluation_cacheObject

Returns the value of attribute evaluation_cache.



3
4
5
# File 'lib/fastcache/interface/evaluator.rb', line 3

def evaluation_cache
  @evaluation_cache
end

Instance Method Details

#cache_eval(key = "", expiration = @default_expiration) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/fastcache/interface/evaluator.rb', line 6

def cache_eval(key = "", expiration = @default_expiration)
  maybe = @evaluation_cache.get(key)
  if maybe.anything?
    Marshal.load(maybe.value)
  else
    value = yield
    @evaluation_cache.set(key, Marshal.dump(value), expiration || 0)
    value
  end
end