Class: Engram::Rails::CacheProcessedTurns
- Inherits:
-
Object
- Object
- Engram::Rails::CacheProcessedTurns
- Includes:
- Ports::ProcessedTurns
- Defined in:
- lib/engram/rails/cache_processed_turns.rb
Overview
ProcessedTurns backed by Rails.cache. Idempotency survives across processes and job retries when a shared cache (e.g. Solid Cache) is configured.
Instance Method Summary collapse
-
#initialize(namespace: "engram:processed_turns", ttl: 86_400) ⇒ CacheProcessedTurns
constructor
A new instance of CacheProcessedTurns.
- #record(key) ⇒ Object
- #seen?(key) ⇒ Boolean
Constructor Details
#initialize(namespace: "engram:processed_turns", ttl: 86_400) ⇒ CacheProcessedTurns
Returns a new instance of CacheProcessedTurns.
10 11 12 13 |
# File 'lib/engram/rails/cache_processed_turns.rb', line 10 def initialize(namespace: "engram:processed_turns", ttl: 86_400) @namespace = namespace @ttl = ttl end |
Instance Method Details
#record(key) ⇒ Object
19 20 21 22 |
# File 'lib/engram/rails/cache_processed_turns.rb', line 19 def record(key) ::Rails.cache.write(cache_key(key), true, expires_in: @ttl) key end |
#seen?(key) ⇒ Boolean
15 16 17 |
# File 'lib/engram/rails/cache_processed_turns.rb', line 15 def seen?(key) ::Rails.cache.exist?(cache_key(key)) end |