class Marten::Cache::Store::Memory

Overview

A cache store implementation that stores data in memory.

Marten::Cache::Store::Memory is a cache implementation that stores all data in memory within the same process, making it a fast and reliable option for caching in single process environments. However, it's worth noting that if you're running multiple instances of your application, the cache data will not be shared between them.

By default, Marten::Cache::Store::Memory does not compress data because it doesn't transmit data over the network. However, compression can be enabled if desired.

Defined in:

marten/cache/store/memory.cr

Constructors

Instance Method Summary

Instance methods inherited from class Marten::Cache::Store::Base

clear clear, 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 decrement, delete(key : String | Symbol) : Bool delete, delete_entry(key : String) : Bool delete_entry, exists?(key : String | Symbol, version : Int32 | Nil = nil) : Bool exists?, 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 fetch, 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 increment, read(key : String | Symbol, raw : Bool = false, version : Int32 | Nil = nil) : String | Nil read, read_entry(key : String) : String | Nil read_entry, 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) write, write_entry(key : String, value : String, expires_in : Time::Span | Nil = nil, race_condition_ttl : Time::Span | Nil = nil) write_entry

Constructor methods inherited from class Marten::Cache::Store::Base

new(namespace : String | Nil = nil, expires_in : Time::Span | Nil = nil, version : Int32 | Nil = nil, compress : Bool = true, compress_threshold : Int32 = DEFAULT_COMPRESS_THRESHOLD) new

Constructor Detail

def self.new(namespace : String | Nil = nil, expires_in : Time::Span | Nil = nil, version : Int32 | Nil = nil, compress = false, compress_threshold = DEFAULT_COMPRESS_THRESHOLD) #

[View source]

Instance Method Detail

def clear : Nil #
Description copied from class Marten::Cache::Store::Base

Clears the entire cache.


[View source]
def 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 #
Description copied from class Marten::Cache::Store::Base

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 to 1)
  • 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.

[View source]
def delete_entry(key : String) : Bool #
Description copied from class Marten::Cache::Store::Base

Deletes an entry from the cache.


[View source]
def 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 #
Description copied from class Marten::Cache::Store::Base

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 to 1)
  • 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.

[View source]
def read_entry(key : String) : String | Nil #
Description copied from class Marten::Cache::Store::Base

Reads an entry from the cache.


[View source]
def write_entry(key : String, value : String, expires_in : Time::Span | Nil = nil, race_condition_ttl : Time::Span | Nil = nil) #
Description copied from class Marten::Cache::Store::Base

Writes an entry to the cache.


[View source]