View Source Cachex.Options (Cachex v3.6.0)

Binding module to parse options into a cache record.

This interim module is required to normalize the options passed to a cache at startup into a well formed record instance, allowing the rest of the codebase to make assumptions about what types of data are being dealt with.

Link to this section Summary

Functions

Retrieves a conditional option from a Keyword List.

Parses a list of cache options into a cache record.

Transforms and returns an option inside a Keyword List.

Link to this section Functions

Link to this function

get(options, key, condition, default \\ nil)

View Source
@spec get(Keyword.t(), atom(), (any() -> boolean()), any()) :: any()

Retrieves a conditional option from a Keyword List.

If the value satisfies the condition provided, it will be returned. Otherwise the default value provided is returned instead. Used for basic validations.

@spec parse(atom(), Keyword.t()) :: {:ok, Cachex.Spec.cache()} | {:error, atom()}

Parses a list of cache options into a cache record.

This will validate any options and error on anything we don't understand. The advantage of binding into a cache instance is that we can blindly use it in other areas of the library without needing to validate. As such, this code can easily become a little messy - but that's ok!

Link to this function

transform(options, key, transformer)

View Source
@spec transform(Keyword.t(), atom(), (any() -> any())) :: any()

Transforms and returns an option inside a Keyword List.