View Source Momento.CacheClient (Momento Elixir SDK v0.4.0)

Client to perform operations against a Momento cache.

Link to this section Summary

Link to this section Types

@opaque t()

Link to this section Functions

Link to this function

create!(config, credential_provider, default_ttl_seconds)

View Source
@spec create!(
  config :: Momento.Config.Configuration.t(),
  credential_provider :: Momento.Auth.CredentialProvider.t(),
  default_ttl_seconds :: float()
) :: 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.
Link to this function

create_cache(client, cache_name)

View Source
@spec create_cache(
  client :: t(),
  cache_name :: String.t()
) :: Momento.Responses.CreateCache.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.
Link to this function

delete(client, cache_name, key)

View Source
@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.
Link to this function

delete_cache(client, cache_name)

View Source
@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.
Link to this function

get(client, cache_name, key)

View Source
@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.
Link to this function

set(client, cache_name, key, value, opts \\ [])

View Source
@spec set(
  client :: t(),
  cache_name :: String.t(),
  key :: binary(),
  value :: binary(),
  opts :: [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.
Link to this function

sorted_set_fetch_by_rank(client, cache_name, sorted_set_name, opts \\ [])

View Source
@spec sorted_set_fetch_by_rank(
  client :: t(),
  cache_name :: String.t(),
  sorted_set_name :: String.t(),
  opts :: [start_rank: integer(), end_rank: integer(), sort_order: :asc | :desc]
) :: Momento.Responses.SortedSet.Fetch.t()
Link to this function

sorted_set_fetch_by_score(client, cache_name, sorted_set_name, opts \\ [])

View Source
@spec sorted_set_fetch_by_score(
  client :: t(),
  cache_name :: String.t(),
  sorted_set_name :: String.t(),
  opts :: [
    min_score: float(),
    max_score: float(),
    offset: integer(),
    count: integer(),
    sort_order: :asc | :desc
  ]
) :: Momento.Responses.SortedSet.Fetch.t()
Link to this function

sorted_set_get_rank(client, cache_name, sorted_set_name, value, opts \\ [])

View Source
@spec sorted_set_get_rank(
  client :: t(),
  cache_name :: String.t(),
  sorted_set_name :: String.t(),
  value :: binary(),
  opts :: [{:sort_order, :asc | :desc}]
) :: Momento.Responses.SortedSet.GetRank.t()
Link to this function

sorted_set_get_score(client, cache_name, sorted_set_name, value)

View Source
@spec sorted_set_get_score(
  client :: t(),
  cache_name :: String.t(),
  sorted_set_name :: String.t(),
  value :: binary()
) :: Momento.Responses.SortedSet.GetScore.t()
Link to this function

sorted_set_get_scores(client, cache_name, sorted_set_name, values)

View Source
@spec sorted_set_get_scores(
  client :: t(),
  cache_name :: String.t(),
  sorted_set_name :: String.t(),
  values :: [binary()]
) :: Momento.Responses.SortedSet.GetScores.t()
Link to this function

sorted_set_increment_score(client, cache_name, sorted_set_name, value, amount, opts \\ [])

View Source
@spec sorted_set_increment_score(
  client :: t(),
  cache_name :: String.t(),
  sorted_set_name :: String.t(),
  value :: binary(),
  amount :: float(),
  opts :: [collection_ttl :: Momento.Requests.CollectionTtl.t()]
) :: Momento.Responses.SortedSet.IncrementScore.t()
Link to this function

sorted_set_put_element(client, cache_name, sorted_set_name, value, score, opts \\ [])

View Source
@spec sorted_set_put_element(
  client :: t(),
  cache_name :: String.t(),
  sorted_set_name :: String.t(),
  value :: binary(),
  score :: float(),
  opts :: [collection_ttl :: Momento.Requests.CollectionTtl.t()]
) :: Momento.Responses.SortedSet.PutElement.t()
Link to this function

sorted_set_put_elements(client, cache_name, sorted_set_name, elements, opts \\ [])

View Source
@spec sorted_set_put_elements(
  client :: t(),
  cache_name :: String.t(),
  sorted_set_name :: String.t(),
  elements :: %{required(binary()) => float()} | [{binary(), float()}],
  opts :: [collection_ttl :: Momento.Requests.CollectionTtl.t()]
) :: Momento.Responses.SortedSet.PutElements.t()
Link to this function

sorted_set_remove_element(client, cache_name, sorted_set_name, value)

View Source
@spec sorted_set_remove_element(
  client :: t(),
  cache_name :: String.t(),
  sorted_set_name :: String.t(),
  value :: binary()
) :: Momento.Responses.SortedSet.RemoveElement.t()
Link to this function

sorted_set_remove_elements(client, cache_name, sorted_set_name, values)

View Source
@spec sorted_set_remove_elements(
  client :: t(),
  cache_name :: String.t(),
  sorted_set_name :: String.t(),
  values :: [binary()]
) :: Momento.Responses.SortedSet.RemoveElements.t()