Simpler Cache v0.1.1 SimplerCache View Source

Simple cache implementation with no locks or other more complicated features.

Link to this section Summary

Functions

Deletes item from cache or does no-op

Returns an item from cache or nil if not found

Gets or stores an item based on a passed in function Warning the below may retry a bit on heavy contention

Inserts new item into cache

Inserts new item or overwrites old item’s value

Sets the ttl to a specific value in ms over 100 for an item

Returns the number of elements in the cache

Updates existing value in cache based on old value Warning the below may retry a bit on heavy contention

Link to this section Types

Link to this type fallback_function() View Source
fallback_function() :: (() -> any())
Link to this type update_function() View Source
update_function() :: (any() -> any())

Link to this section Functions

Link to this function delete(key) View Source
delete(any()) :: {:ok, :deleted} | {:ok, :not_found}

Deletes item from cache or does no-op

Link to this function get(key) View Source
get(any()) :: nil | any()

Returns an item from cache or nil if not found

Link to this function get_or_store(key, passed_fn) View Source
get_or_store(any(), fallback_function()) :: any()

Gets or stores an item based on a passed in function Warning the below may retry a bit on heavy contention

Link to this function insert_new(key, value) View Source
insert_new(any(), any()) ::
  {:ok, :inserted} | {:error, :item_is_in_cache} | {:error, any()}

Inserts new item into cache

Link to this function put(key, value) View Source
put(any(), any()) :: {:ok, :inserted} | {:error, any()}

Inserts new item or overwrites old item’s value

Link to this function set_ttl_ms(key, time_ms) View Source
set_ttl_ms(any(), pos_integer()) ::
  {:ok, :updated} | {:error, :failed_to_update_element} | {:error, any()}

Sets the ttl to a specific value in ms over 100 for an item

Returns the number of elements in the cache

Link to this function update_existing(key, passed_fn) View Source
update_existing(any(), update_function()) ::
  {:ok, :updated} | {:error, :failed_to_find_entry}

Updates existing value in cache based on old value Warning the below may retry a bit on heavy contention