Class: Tina4::CacheBackends::BaseBackend
- Inherits:
-
Object
- Object
- Tina4::CacheBackends::BaseBackend
- Defined in:
- lib/tina4/cache_backends/base_backend.rb
Overview
Abstract cache backend (parity with Python _CacheBackend).
A backend is a key/value store with TTL semantics and stats. Values are arbitrary JSON-serialisable objects; backends round-trip them through JSON for the network/file/db tiers so a value stored by one process can be read by another. The factory (Tina4::CacheBackends.create_backend) picks the right implementation from env vars and falls back to the file backend when a configured network/driver backend is unreachable.
Direct Known Subclasses
DatabaseBackend, FileBackend, MemcachedBackend, MemoryBackend, MongoBackend, RedisBackend
Instance Method Summary collapse
-
#available? ⇒ Boolean
Whether this backend is actually usable (driver present + service reachable).
-
#clear ⇒ Object
Remove all entries owned by this cache.
-
#delete(_key) ⇒ Boolean
True if the key existed.
-
#get(_key) ⇒ Object?
Cached value or nil on miss/expiry.
-
#name ⇒ String
Backend name reported in stats.
- #set(_key, _value, _ttl) ⇒ Object
-
#stats ⇒ Hash
{ hits:, misses:, size:, backend: }.
Instance Method Details
#available? ⇒ Boolean
Whether this backend is actually usable (driver present + service reachable). Local backends are always available; network/driver backends override this so the factory can fall back to the file backend.
53 54 55 |
# File 'lib/tina4/cache_backends/base_backend.rb', line 53 def available? true end |
#clear ⇒ Object
Remove all entries owned by this cache.
34 35 36 |
# File 'lib/tina4/cache_backends/base_backend.rb', line 34 def clear raise NotImplementedError end |
#delete(_key) ⇒ Boolean
Returns true if the key existed.
29 30 31 |
# File 'lib/tina4/cache_backends/base_backend.rb', line 29 def delete(_key) raise NotImplementedError end |
#get(_key) ⇒ Object?
Returns cached value or nil on miss/expiry.
16 17 18 |
# File 'lib/tina4/cache_backends/base_backend.rb', line 16 def get(_key) raise NotImplementedError end |
#name ⇒ String
Returns backend name reported in stats.
44 45 46 |
# File 'lib/tina4/cache_backends/base_backend.rb', line 44 def name raise NotImplementedError end |
#set(_key, _value, _ttl) ⇒ Object
23 24 25 |
# File 'lib/tina4/cache_backends/base_backend.rb', line 23 def set(_key, _value, _ttl) raise NotImplementedError end |
#stats ⇒ Hash
Returns { hits:, misses:, size:, backend: }.
39 40 41 |
# File 'lib/tina4/cache_backends/base_backend.rb', line 39 def stats raise NotImplementedError end |