Memcache.cas

You're seeing just the function cas, go back to Memcache module for more information.
Link to this function

cas(server, key, update, opts \\ [])

View Source

Specs

cas(GenServer.server(), binary(), (value() -> value()), Keyword.t()) ::
  {:ok, any()} | error()

Compare and swap value using optimistic locking.

"Happy path":

  1. Get the existing value for key
  2. If it exists, call the update function with the value
  3. Set the returned value for key

The update can be retried in case an intervening update happened.

A default value can also be provided, to be used if the key does not yet exist.

See the description of options below for details.

Options

  • :retry - whether the update should be retried if someone else has updated the value for the same key in the meantime. Defaults to true.

  • :ttl - TTL for the updated key. Defaults to the TTL passed when starting the server via start_link/2, or infinity if none was given there either.

  • :default - a default value to use if the key does not yet exist. If a 0-arity function is passed for this value, the default value will be lazily evaluated only when needed. This is useful in cases where the default is expensive to compute. If a :default opt is not passed, the function will return {:error, "Key not found"} when attempting to update a nonexistent key.
    NOTE: If a key is created after the initial GET and before the default value is ADDed, the update will be retried at least once regardless of the value of the :retry opt.