Class: Ukiryu::Definition::DefinitionCache::Entry
- Inherits:
-
Object
- Object
- Ukiryu::Definition::DefinitionCache::Entry
- Defined in:
- lib/ukiryu/definition/definition_cache.rb
Overview
Cache entry structure
Instance Attribute Summary collapse
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
-
#loaded_at ⇒ Object
readonly
Returns the value of attribute loaded_at.
-
#mtime ⇒ Object
readonly
Returns the value of attribute mtime.
-
#source_key ⇒ Object
readonly
Returns the value of attribute source_key.
Instance Method Summary collapse
-
#initialize(definition, mtime: nil, source_key: nil) ⇒ Entry
constructor
A new instance of Entry.
-
#refresh ⇒ Entry
Refresh the entry.
-
#stale?(ttl: DEFAULT_TTL) ⇒ Boolean
Check if entry is stale.
Constructor Details
#initialize(definition, mtime: nil, source_key: nil) ⇒ Entry
Returns a new instance of Entry.
19 20 21 22 23 24 |
# File 'lib/ukiryu/definition/definition_cache.rb', line 19 def initialize(definition, mtime: nil, source_key: nil) @definition = definition @mtime = mtime @loaded_at = Time.now @source_key = source_key || generate_source_key(definition) end |
Instance Attribute Details
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
17 18 19 |
# File 'lib/ukiryu/definition/definition_cache.rb', line 17 def definition @definition end |
#loaded_at ⇒ Object (readonly)
Returns the value of attribute loaded_at.
17 18 19 |
# File 'lib/ukiryu/definition/definition_cache.rb', line 17 def loaded_at @loaded_at end |
#mtime ⇒ Object (readonly)
Returns the value of attribute mtime.
17 18 19 |
# File 'lib/ukiryu/definition/definition_cache.rb', line 17 def mtime @mtime end |
#source_key ⇒ Object (readonly)
Returns the value of attribute source_key.
17 18 19 |
# File 'lib/ukiryu/definition/definition_cache.rb', line 17 def source_key @source_key end |
Instance Method Details
#refresh ⇒ Entry
Refresh the entry
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ukiryu/definition/definition_cache.rb', line 46 def refresh if @definition.respond_to?(:load_definition) # Reload from metadata new_def = @definition.load_definition Entry.new(new_def, mtime: new_def.mtime, source_key: @source_key) else # Can't refresh, return as-is self end end |
#stale?(ttl: DEFAULT_TTL) ⇒ Boolean
Check if entry is stale
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ukiryu/definition/definition_cache.rb', line 30 def stale?(ttl: DEFAULT_TTL) # Check TTL return true if Time.now - @loaded_at > ttl # Check mtime for file-based definitions if @mtime && @definition.respond_to?(:path) path = @definition.path return true if path && File.exist?(path) && File.mtime(path) > @mtime end false end |