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.



121
122
123
124
# File 'lib/fontist/cache/store.rb', line 121

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.



119
120
121
# File 'lib/fontist/cache/store.rb', line 119

def expires_at
  @expires_at
end

#valueObject (readonly)

Returns the value of attribute value.



119
120
121
# File 'lib/fontist/cache/store.rb', line 119

def value
  @value
end

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)


126
127
128
# File 'lib/fontist/cache/store.rb', line 126

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