Class: Lutaml::Store::CacheStore::CacheEntry
- Inherits:
-
Object
- Object
- Lutaml::Store::CacheStore::CacheEntry
- Defined in:
- lib/lutaml/store/cache_store.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#ttl ⇒ Object
readonly
Returns the value of attribute ttl.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #expired? ⇒ Boolean
- #expires_at ⇒ Object
-
#initialize(value, ttl: nil, metadata: {}, created_at: nil) ⇒ CacheEntry
constructor
A new instance of CacheEntry.
- #to_h ⇒ Object
Constructor Details
#initialize(value, ttl: nil, metadata: {}, created_at: nil) ⇒ CacheEntry
Returns a new instance of CacheEntry.
12 13 14 15 16 17 |
# File 'lib/lutaml/store/cache_store.rb', line 12 def initialize(value, ttl: nil, metadata: {}, created_at: nil) @value = value @created_at = created_at || Time.now @ttl = ttl @metadata = end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
10 11 12 |
# File 'lib/lutaml/store/cache_store.rb', line 10 def created_at @created_at end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
10 11 12 |
# File 'lib/lutaml/store/cache_store.rb', line 10 def @metadata end |
#ttl ⇒ Object (readonly)
Returns the value of attribute ttl.
10 11 12 |
# File 'lib/lutaml/store/cache_store.rb', line 10 def ttl @ttl end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
10 11 12 |
# File 'lib/lutaml/store/cache_store.rb', line 10 def value @value end |
Class Method Details
.from_h(hash) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/lutaml/store/cache_store.rb', line 41 def self.from_h(hash) new( hash[:value], ttl: hash[:ttl], metadata: hash[:metadata] || {}, created_at: Time.parse(hash[:created_at]) ) end |
Instance Method Details
#expired? ⇒ Boolean
19 20 21 22 23 |
# File 'lib/lutaml/store/cache_store.rb', line 19 def expired? return false unless @ttl Time.now - @created_at > @ttl end |
#expires_at ⇒ Object
25 26 27 28 29 |
# File 'lib/lutaml/store/cache_store.rb', line 25 def expires_at return nil unless @ttl @created_at + @ttl end |
#to_h ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/lutaml/store/cache_store.rb', line 31 def to_h { value: @value, created_at: @created_at.iso8601, ttl: @ttl, expires_at: expires_at&.iso8601, metadata: @metadata } end |