Class: Fontist::Cache::Store::CacheEntry

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

Overview

Cache entry with TTL support

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, ttl) ⇒ CacheEntry

Returns a new instance of CacheEntry.



111
112
113
114
# File 'lib/fontist/cache/store.rb', line 111

def initialize(value, ttl)
  @value = value
  @expires_at = ttl ? (Time.now + ttl).to_i : nil
end

Instance Attribute Details

#expires_atObject (readonly)

Returns the value of attribute expires_at.



109
110
111
# File 'lib/fontist/cache/store.rb', line 109

def expires_at
  @expires_at
end

#valueObject (readonly)

Returns the value of attribute value.



109
110
111
# File 'lib/fontist/cache/store.rb', line 109

def value
  @value
end

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/fontist/cache/store.rb', line 116

def expired?
  !!(@expires_at && Time.now.to_i > @expires_at)
end