Class: Factorix::Cache::Base Abstract
- Inherits:
-
Object
- Object
- Factorix::Cache::Base
- Defined in:
- lib/factorix/cache/base.rb
Overview
Subclasses must implement all abstract methods.
Abstract base class for cache backends.
All cache backends (FileSystem, S3, Redis) inherit from this class and implement the abstract methods defined here.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#ttl ⇒ Integer?
readonly
Time-to-live in seconds (nil for unlimited).
Instance Method Summary collapse
-
#age(key) ⇒ Float?
abstract
Get the age of a cache entry in seconds.
-
#backend_info ⇒ Hash
Return backend-specific information.
-
#clear ⇒ void
abstract
Clear all cache entries.
-
#delete(key) ⇒ Boolean
abstract
Delete a cache entry.
-
#each {|key, entry| ... } ⇒ Enumerator
abstract
Enumerate cache entries.
-
#exist?(key) ⇒ Boolean
abstract
Check if a cache entry exists and is not expired.
-
#expired?(key) ⇒ Boolean
abstract
Check if a cache entry has expired based on TTL.
-
#initialize(ttl: nil) ⇒ Base
constructor
Initialize a new cache backend.
-
#read(key) ⇒ String?
abstract
Read a cached entry as a string.
-
#size(key) ⇒ Integer?
abstract
Get the size of a cached entry in bytes.
-
#store(key, src) ⇒ Boolean
abstract
Store data in the cache.
-
#with_lock(key) { ... } ⇒ Object
abstract
Execute a block with an exclusive lock on the cache entry.
-
#write_to(key, output) ⇒ Boolean
abstract
Write cached content to a file.
Constructor Details
#initialize(ttl: nil) ⇒ Base
Initialize a new cache backend.
18 19 20 |
# File 'lib/factorix/cache/base.rb', line 18 def initialize(ttl: nil) @ttl = ttl end |
Instance Attribute Details
#ttl ⇒ Integer? (readonly)
Returns time-to-live in seconds (nil for unlimited).
13 14 15 |
# File 'lib/factorix/cache/base.rb', line 13 def ttl @ttl end |
Instance Method Details
#age(key) ⇒ Float?
Get the age of a cache entry in seconds.
80 |
# File 'lib/factorix/cache/base.rb', line 80 def age(key) = raise NotImplementedError, "#{self.class}#age must be implemented" |
#backend_info ⇒ Hash
Return backend-specific information.
Subclasses should override this method to provide configuration details specific to their backend implementation.
113 |
# File 'lib/factorix/cache/base.rb', line 113 def backend_info = {} |
#clear ⇒ void
This method returns an undefined value.
Clear all cache entries.
66 |
# File 'lib/factorix/cache/base.rb', line 66 def clear = raise NotImplementedError, "#{self.class}#clear must be implemented" |
#delete(key) ⇒ Boolean
Delete a cache entry.
60 |
# File 'lib/factorix/cache/base.rb', line 60 def delete(key) = raise NotImplementedError, "#{self.class}#delete must be implemented" |
#each {|key, entry| ... } ⇒ Enumerator
Enumerate cache entries.
Yields [key, entry] pairs similar to Hash#each.
105 |
# File 'lib/factorix/cache/base.rb', line 105 def each = raise NotImplementedError, "#{self.class}#each must be implemented" |
#exist?(key) ⇒ Boolean
Check if a cache entry exists and is not expired.
27 |
# File 'lib/factorix/cache/base.rb', line 27 def exist?(key) = raise NotImplementedError, "#{self.class}#exist? must be implemented" |
#expired?(key) ⇒ Boolean
Check if a cache entry has expired based on TTL.
87 |
# File 'lib/factorix/cache/base.rb', line 87 def expired?(key) = raise NotImplementedError, "#{self.class}#expired? must be implemented" |
#read(key) ⇒ String?
Read a cached entry as a string.
34 |
# File 'lib/factorix/cache/base.rb', line 34 def read(key) = raise NotImplementedError, "#{self.class}#read must be implemented" |
#size(key) ⇒ Integer?
Get the size of a cached entry in bytes.
94 |
# File 'lib/factorix/cache/base.rb', line 94 def size(key) = raise NotImplementedError, "#{self.class}#size must be implemented" |
#store(key, src) ⇒ Boolean
Store data in the cache.
53 |
# File 'lib/factorix/cache/base.rb', line 53 def store(key, src) = raise NotImplementedError, "#{self.class}#store must be implemented" |
#with_lock(key) { ... } ⇒ Object
Execute a block with an exclusive lock on the cache entry.
73 |
# File 'lib/factorix/cache/base.rb', line 73 def with_lock(key) = raise NotImplementedError, "#{self.class}#with_lock must be implemented" |
#write_to(key, output) ⇒ Boolean
Write cached content to a file.
Unlike #read which returns content as a String, this method writes directly to a file path, which is more memory-efficient for large files.
45 |
# File 'lib/factorix/cache/base.rb', line 45 def write_to(key, output) = raise NotImplementedError, "#{self.class}#write_to must be implemented" |