Class: Optimizely::CacheElement

Inherits:
Object
  • Object
show all
Defined in:
lib/optimizely/odp/lru_cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ CacheElement

Returns a new instance of CacheElement.



100
101
102
103
# File 'lib/optimizely/odp/lru_cache.rb', line 100

def initialize(value)
  @value = value
  @timestamp = Time.new
end

Instance Attribute Details

#timestampObject (readonly)

Individual element for the LRUCache.



98
99
100
# File 'lib/optimizely/odp/lru_cache.rb', line 98

def timestamp
  @timestamp
end

#valueObject (readonly)

Individual element for the LRUCache.



98
99
100
# File 'lib/optimizely/odp/lru_cache.rb', line 98

def value
  @value
end

Instance Method Details

#stale?(timeout) ⇒ Boolean

Returns:

  • (Boolean)


105
106
107
108
109
110
111
112
# File 'lib/optimizely/odp/lru_cache.rb', line 105

def stale?(timeout)
  # Returns true if the provided timeout has passed since the element's timestamp.
  #
  # @param timeout - The duration to check against
  return false if timeout <= 0

  Time.new - @timestamp >= timeout
end