Class: ActiveMatrix::AgentStore
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ActiveMatrix::AgentStore
- Defined in:
- app/models/active_matrix/agent_store.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#cache_key ⇒ Object
Cache integration.
- #expired? ⇒ Boolean
- #ttl ⇒ Object
- #ttl=(seconds) ⇒ Object
- #write_to_cache ⇒ Object
Class Method Details
.cleanup_expired! ⇒ Object
41 42 43 |
# File 'app/models/active_matrix/agent_store.rb', line 41 def self.cleanup_expired! expired.destroy_all end |
Instance Method Details
#cache_key ⇒ Object
Cache integration
33 34 35 |
# File 'app/models/active_matrix/agent_store.rb', line 33 def cache_key "agent_memory/#{agent_id}/#{key}" end |
#expired? ⇒ Boolean
17 18 19 |
# File 'app/models/active_matrix/agent_store.rb', line 17 def expired? expires_at.present? && expires_at <= Time.current end |
#ttl ⇒ Object
25 26 27 28 29 30 |
# File 'app/models/active_matrix/agent_store.rb', line 25 def ttl return nil if expires_at.blank? remaining = expires_at - Time.current [remaining, 0].max end |
#ttl=(seconds) ⇒ Object
21 22 23 |
# File 'app/models/active_matrix/agent_store.rb', line 21 def ttl=(seconds) self.expires_at = seconds.present? ? Time.current + seconds : nil end |
#write_to_cache ⇒ Object
37 38 39 |
# File 'app/models/active_matrix/agent_store.rb', line 37 def write_to_cache Rails.cache.write(cache_key, value, expires_in: ttl) end |