View Source Momento.CacheClient (Momento Elixir SDK v0.2.0)
Client to perform operations against a Momento cache.
Link to this section Summary
Functions
Creates a new CacheClient instance.
Creates a cache if it does not exist.
Delete a value from the cache.
Deletes a cache and all items stored in it.
Get a value from the cache.
List all caches.
Set the value in cache with a given time to live (TTL) seconds.
Link to this section Types
@opaque t()
Link to this section Functions
@spec create!( config :: Momento.Configuration.t(), credential_provider :: Momento.Auth.CredentialProvider.t() ) :: t()
Creates a new CacheClient instance.
parameters
Parameters
config
: A struct containing all tunable client settings.credential_provider
: A struct representing the credentials to connect to the server.
returns
Returns
- A
%Momento.CacheClient{}
struct representing the connected client.
@spec create_cache( client :: t(), cache_name :: String.t() ) :: Momento.Responses.DeleteCache.t()
Creates a cache if it does not exist.
parameters
Parameters
client
: A%Momento.CacheClient{}
struct representing the connected client.cache_name
: The name of the cache to create. Must be a string.
returns
Returns
{:ok, %Momento.Responses.CreateCache.Ok{}}
on a successful create.:already_exists
if a cache with the specified name already exists.{:error, error}
tuple if an error occurs.
@spec delete(client :: t(), cache_name :: String.t(), key :: binary()) :: Momento.Responses.Delete.t()
Delete a value from the cache.
parameters
Parameters
client
: A%Momento.CacheClient{}
struct representing the connected client.cache_name
: The name of the cache to fetch the value from. Must be a string.key
: The key of the value to fetch. Must be a binary.
returns
Returns
{:ok, %Momento.Responses.Delete.Ok{}}
on a successful deletion.{:error, error}
tuple if an error occurs.
@spec delete_cache( client :: t(), cache_name :: String.t() ) :: Momento.Responses.DeleteCache.t()
Deletes a cache and all items stored in it.
parameters
Parameters
client
: A%Momento.CacheClient{}
struct representing the connected client.cache_name
: The name of the cache to delete. Must be a string.
returns
Returns
{:ok, %Momento.Responses.DeleteCache.Ok{}}
on a successful delete.{:error, error}
tuple if an error occurs.
@spec get(client :: t(), cache_name :: String.t(), key :: binary()) :: Momento.Responses.Get.t()
Get a value from the cache.
parameters
Parameters
client
: A%Momento.CacheClient{}
struct representing the connected client.cache_name
: The name of the cache to fetch the value from. Must be a string.key
: The key of the value to fetch. Must be a binary.
returns
Returns
{:ok, %Momento.Responses.Get.Hit{value: value}}
tuple if the key exists.:miss
if the key does not exist.{:error, error}
tuple if an error occurs.
@spec list_caches(client :: t()) :: Momento.Responses.ListCaches.t()
List all caches.
parameters
Parameters
client
: A%Momento.CacheClient{}
struct representing the connected client.
returns
Returns
{:ok, %Momento.Responses.ListCaches.Ok{caches: caches}}
on a successful listing.{:error, error}
tuple if an error occurs.
@spec set( client :: t(), cache_name :: String.t(), key :: binary(), value :: binary(), ttl_seconds :: float() ) :: Momento.Responses.Set.t()
Set the value in cache with a given time to live (TTL) seconds.
parameters
Parameters
client
: A%Momento.CacheClient{}
struct representing the connected client.cache_name
: The name of the cache to store the value in. Must be a string.key
: The key to store the value under. Must be a binary.value
: The value to be stored. Must be a binary.ttl_seconds
: The time-to-live of the cache entry in seconds. Must be positive.
returns
Returns
{:ok, %Momento.Responses.Set.Ok{}}
on a successful set.{:error, error}
tuple if an error occurs.