Class: Smith::PersistenceAdapters::CacheStore
- Inherits:
-
Object
- Object
- Smith::PersistenceAdapters::CacheStore
- Defined in:
- lib/smith/persistence_adapters/cache_store.rb
Direct Known Subclasses
Constant Summary collapse
- TRANSIENT_ERRORS =
Cache backends vary widely; the transient list is intentionally broad. Hosts using a specific backend can subclass and tighten. NOTE: NO store_versioned implementation — cache backends don’t have uniform CAS semantics. Workflow#persist! checks via respond_to? and falls back to non-versioned store + warning.
[ Errno::ECONNREFUSED, Errno::ETIMEDOUT, Errno::EPIPE, IOError ].freeze
Instance Method Summary collapse
- #backend_name ⇒ Object
- #delete(key) ⇒ Object
- #durability_warning ⇒ Object
- #fetch(key) ⇒ Object
-
#initialize(store:, namespace: "smith") ⇒ CacheStore
constructor
A new instance of CacheStore.
- #store(key, payload, ttl: Smith.config.persistence_ttl) ⇒ Object
Constructor Details
#initialize(store:, namespace: "smith") ⇒ CacheStore
Returns a new instance of CacheStore.
18 19 20 21 |
# File 'lib/smith/persistence_adapters/cache_store.rb', line 18 def initialize(store:, namespace: "smith") @store_source = store @namespace = namespace end |
Instance Method Details
#backend_name ⇒ Object
45 46 47 |
# File 'lib/smith/persistence_adapters/cache_store.rb', line 45 def backend_name backend.class.name || backend.class.to_s end |
#delete(key) ⇒ Object
39 40 41 42 43 |
# File 'lib/smith/persistence_adapters/cache_store.rb', line 39 def delete(key) Retry.with_retries(operation: :delete, transient: TRANSIENT_ERRORS) do backend.delete(namespaced(key)) end end |
#durability_warning ⇒ Object
49 50 51 |
# File 'lib/smith/persistence_adapters/cache_store.rb', line 49 def durability_warning process_local_backend_warning end |
#fetch(key) ⇒ Object
33 34 35 36 37 |
# File 'lib/smith/persistence_adapters/cache_store.rb', line 33 def fetch(key) Retry.with_retries(operation: :fetch, transient: TRANSIENT_ERRORS) do backend.read(namespaced(key)) end end |
#store(key, payload, ttl: Smith.config.persistence_ttl) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/smith/persistence_adapters/cache_store.rb', line 23 def store(key, payload, ttl: Smith.config.persistence_ttl) Retry.with_retries(operation: :store, transient: TRANSIENT_ERRORS) do if ttl backend.write(namespaced(key), payload, expires_in: ttl) else backend.write(namespaced(key), payload) end end end |