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
70 71 72 |
# File 'app/models/active_matrix/agent_store.rb', line 70 def self.cleanup_expired! expired.destroy_all end |
Instance Method Details
#cache_key ⇒ Object
Cache integration
62 63 64 |
# File 'app/models/active_matrix/agent_store.rb', line 62 def cache_key "agent_memory/#{agent_id}/#{key}" end |
#expired? ⇒ Boolean
46 47 48 |
# File 'app/models/active_matrix/agent_store.rb', line 46 def expired? expires_at.present? && expires_at <= Time.current end |
#ttl ⇒ Object
54 55 56 57 58 59 |
# File 'app/models/active_matrix/agent_store.rb', line 54 def ttl return nil if expires_at.blank? remaining = expires_at - Time.current [remaining, 0].max end |
#ttl=(seconds) ⇒ Object
50 51 52 |
# File 'app/models/active_matrix/agent_store.rb', line 50 def ttl=(seconds) self.expires_at = seconds.present? ? Time.current + seconds : nil end |
#write_to_cache ⇒ Object
66 67 68 |
# File 'app/models/active_matrix/agent_store.rb', line 66 def write_to_cache Rails.cache.write(cache_key, value, expires_in: ttl) end |