Class: AgentMemory
- Defined in:
- lib/generators/active_matrix/install/templates/agent_memory.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
38 39 40 |
# File 'lib/generators/active_matrix/install/templates/agent_memory.rb', line 38 def self.cleanup_expired! expired.destroy_all end |
Instance Method Details
#cache_key ⇒ Object
Cache integration
30 31 32 |
# File 'lib/generators/active_matrix/install/templates/agent_memory.rb', line 30 def cache_key "agent_memory/#{matrix_agent_id}/#{key}" end |
#expired? ⇒ Boolean
14 15 16 |
# File 'lib/generators/active_matrix/install/templates/agent_memory.rb', line 14 def expired? expires_at.present? && expires_at <= Time.current end |
#ttl ⇒ Object
22 23 24 25 26 27 |
# File 'lib/generators/active_matrix/install/templates/agent_memory.rb', line 22 def ttl return nil unless expires_at.present? remaining = expires_at - Time.current [remaining, 0].max end |
#ttl=(seconds) ⇒ Object
18 19 20 |
# File 'lib/generators/active_matrix/install/templates/agent_memory.rb', line 18 def ttl=(seconds) self.expires_at = seconds.present? ? Time.current + seconds : nil end |
#write_to_cache ⇒ Object
34 35 36 |
# File 'lib/generators/active_matrix/install/templates/agent_memory.rb', line 34 def write_to_cache Rails.cache.write(cache_key, value, expires_in: ttl) end |