Class: Textus::Lanes::Artifact::Cache
- Inherits:
-
Object
- Object
- Textus::Lanes::Artifact::Cache
- Defined in:
- lib/textus/lanes/artifact/cache.rb
Instance Method Summary collapse
- #expire(key) ⇒ Object
-
#initialize(store, ttl_default: 3600 * 24 * 30) ⇒ Cache
constructor
A new instance of Cache.
- #stale?(key) ⇒ Boolean
- #ttl(key) ⇒ Object
Constructor Details
#initialize(store, ttl_default: 3600 * 24 * 30) ⇒ Cache
Returns a new instance of Cache.
5 6 7 8 |
# File 'lib/textus/lanes/artifact/cache.rb', line 5 def initialize(store, ttl_default: 3600 * 24 * 30) @store = store @ttl_default = ttl_default end |
Instance Method Details
#expire(key) ⇒ Object
29 30 31 |
# File 'lib/textus/lanes/artifact/cache.rb', line 29 def expire(key) @store.put(key:, meta: { "stale" => true }) end |
#stale?(key) ⇒ Boolean
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/textus/lanes/artifact/cache.rb', line 17 def stale?(key) entry = @store.get(key:) return true unless entry return true if entry["stale"] || entry["fetching"] generated_at = entry["generated_at"] return true unless generated_at age = Time.now - Time.parse(generated_at) age > ttl(key) end |
#ttl(key) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/textus/lanes/artifact/cache.rb', line 10 def ttl(key) entry = @store.get(key:) return @ttl_default unless entry entry["ttl"] || @ttl_default end |