abstract class Marten::Cache::Store::Base
- Marten::Cache::Store::Base
- Reference
- Object
Overview
Abstract base cache store.
Direct Known Subclasses
Defined in:
marten/cache/store/base.crConstant Summary
-
DEFAULT_COMPRESS_THRESHOLD =
1024
Constructors
-
.new(namespace : String | Nil = nil, expires_in : Time::Span | Nil = nil, version : Int32 | Nil = nil, compress : Bool = true, compress_threshold : Int32 = DEFAULT_COMPRESS_THRESHOLD)
Initializes a new cache store.
Instance Method Summary
-
#clear
Clears the entire cache.
-
#decrement(key : String, amount : Int32 = 1, expires_at : Time | Nil = nil, expires_in : Time::Span | Nil = nil, version : Int32 | Nil = nil, race_condition_ttl : Time::Span | Nil = nil, compress : Bool | Nil = nil, compress_threshold : Int32 | Nil = nil) : Int
Decrements the integer value associated with the given
key
. -
#delete(key : String | Symbol) : Bool
Deletes an entry associated with a given
key
from the cache. -
#delete_entry(key : String) : Bool
Deletes an entry from the cache.
-
#exists?(key : String | Symbol, version : Int32 | Nil = nil) : Bool
Returns
true
if an entry associated with the givenkey
exists in the cache. -
#fetch(key : String | Symbol, expires_at : Time | Nil = nil, expires_in : Time::Span | Nil = nil, version : Int32 | Nil = nil, force = false, race_condition_ttl : Time::Span | Nil = nil, compress : Bool | Nil = nil, compress_threshold : Int32 | Nil = nil, &) : String | Nil
Fetches data from the cache by using the given
key
. -
#increment(key : String, amount : Int32 = 1, expires_at : Time | Nil = nil, expires_in : Time::Span | Nil = nil, version : Int32 | Nil = nil, race_condition_ttl : Time::Span | Nil = nil, compress : Bool | Nil = nil, compress_threshold : Int32 | Nil = nil) : Int
Increments the integer value associated with the given
key
. -
#read(key : String | Symbol, raw : Bool = false, version : Int32 | Nil = nil) : String | Nil
Reads data from the cache by using the given
key
. -
#read_entry(key : String) : String | Nil
Reads an entry from the cache.
-
#write(key : String | Symbol, value : String, raw : Bool = false, expires_at : Time | Nil = nil, expires_in : Time::Span | Nil = nil, version : Int32 | Nil = nil, race_condition_ttl : Time::Span | Nil = nil, compress : Bool | Nil = nil, compress_threshold : Int32 | Nil = nil)
Writes
value
into the cache by using the givenkey
. -
#write_entry(key : String, value : String, expires_in : Time::Span | Nil = nil, race_condition_ttl : Time::Span | Nil = nil)
Writes an entry to the cache.
Constructor Detail
Initializes a new cache store.
The following options are supported:
namespace
allows to associate a namespace value with the cache, which can be helpful if the underlying cache system is shared with other applications. Using a namespace will ensure that all they keys are properly prefixed in order to avoid collisions.expires_in
allows to specify a default relative expiration time for cache entries.version
allows to specify a default version value for the entries of the cache. When fetching entries, a mismatch between an entry's version and the requested version is treated like a cache miss.compress
allows to specify whether new entries written to the cache should be compressed.compress_threshold
allows to specify a custom compression threshold. The compression threshold determines whether cached entries are compressed: if these entries are larger than the compression threshold (which is expressed in bytes), then they will be compressed.
Instance Method Detail
Decrements the integer value associated with the given key
.
It should be noted that this method supports a set of optional arguments:
amount
allows to specify the amount used to decrement the integer value (defaults to1
)expires_at
allows to specify an absolute expiration time.expires_in
allows to specify a relative expiration time.version
allows to specify a version value for the entry to write into the cache. When fetching entries, a mismatch between an entry's version and the requested version is treated like a cache miss.race_condition_ttl
allows to specify a relative period of time during which an expired value is allowed to be returned while the new value is being generated and written to the cache. By leveraging this capability, it is possible to ensure that multiple processes that access an expired cache entry at the same time don't end up regenerating the new entry all at the same time.compress
allows to specify whether new entries written to the cache should be compressed.compress_threshold
allows to specify a custom compression threshold. The compression threshold determines whether cached entries are compressed: if these entries are larger than the compression thresholed (which is expressed in bytes), then they will be compressed.
Deletes an entry associated with a given key
from the cache. Returns true
if an entry was deleted.
Returns true
if an entry associated with the given key
exists in the cache.
The #exists?
method allows specifying an additional version
argument, which will be used when checking for
the existence of the entry. When fetching entries, a mismatch between an entry's version and the requested
version is treated like a cache miss.
Fetches data from the cache by using the given key
.
If the specified key
is associated with some data in the cache, then this data is returned. Otherwise, the
return value of the block will be written to the cache and returned by this method.
It should be noted that this method supports a set of optional arguments:
expires_at
allows to specify an absolute expiration time.expires_in
allows to specify a relative expiration time.version
allows to specify a version value for the entry to fetch/write into the cache. When fetching entries, a mismatch between an entry's version and the requested version is treated like a cache miss.force
allows to force a cache miss, resulting in the return value of the block to be written to the cache.race_condition_ttl
allows to specify a relative period of time during which an expired value is allowed to be returned while the new value is being generated and written to the cache. By leveraging this capability, it is possible to ensure that multiple processes that access an expired cache entry at the same time don't end up regenerating the new entry all at the same time.compress
allows to specify whether new entries written to the cache should be compressed.compress_threshold
allows to specify a custom compression threshold. The compression threshold determines whether cached entries are compressed: if these entries are larger than the compression threshold (which is expressed in bytes), then they will be compressed.
Increments the integer value associated with the given key
.
It should be noted that this method supports a set of optional arguments:
amount
allows to specify the amount used to increment the integer value (defaults to1
)expires_at
allows to specify an absolute expiration time.expires_in
allows to specify a relative expiration time.version
allows to specify a version value for the entry to write into the cache. When fetching entries, a mismatch between an entry's version and the requested version is treated like a cache miss.race_condition_ttl
allows to specify a relative period of time during which an expired value is allowed to be returned while the new value is being generated and written to the cache. By leveraging this capability, it is possible to ensure that multiple processes that access an expired cache entry at the same time don't end up regenerating the new entry all at the same time.compress
allows to specify whether new entries written to the cache should be compressed.compress_threshold
allows to specify a custom compression threshold. The compression threshold determines whether cached entries are compressed: if these entries are larger than the compression thresholed (which is expressed in bytes), then they will be compressed.
Reads data from the cache by using the given key
.
This method returns the entry value for the given key
if one exists in the cache. Otherwise nil
is
returned.
The #read
method allows specifying an additional version
argument. When fetching entries, a mismatch
between an entry's version and the requested version is treated like a cache miss.
Writes value
into the cache by using the given key
.
It should be noted that this method supports a set of optional arguments:
expires_at
allows to specify an absolute expiration time.expires_in
allows to specify a relative expiration time.version
allows to specify a version value for the entry to write into the cache. When fetching entries, a mismatch between an entry's version and the requested version is treated like a cache miss.race_condition_ttl
allows to specify a relative period of time during which an expired value is allowed to be returned while the new value is being generated and written to the cache. By leveraging this capability, it is possible to ensure that multiple processes that access an expired cache entry at the same time don't end up regenerating the new entry all at the same time.compress
allows to specify whether new entries written to the cache should be compressed.compress_threshold
allows to specify a custom compression threshold. The compression threshold determines whether cached entries are compressed: if these entries are larger than the compression thresholed (which is expressed in bytes), then they will be compressed.
Writes an entry to the cache.