Class: Apnotic::InstanceCache

Inherits:
Object
  • Object
show all
Defined in:
lib/apnotic/instance_cache.rb

Instance Method Summary collapse

Constructor Details

#initialize(instance, method, ttl) ⇒ InstanceCache

Returns a new instance of InstanceCache.



3
4
5
6
7
# File 'lib/apnotic/instance_cache.rb', line 3

def initialize(instance, method, ttl)
  @instance = instance
  @method   = method
  @ttl      = ttl
end

Instance Method Details

#callObject



9
10
11
12
13
14
15
# File 'lib/apnotic/instance_cache.rb', line 9

def call
  if @cached_value && !expired?
    @cached_value
  else
    new_value
  end
end