Cachex v3.1.3 Cachex.Spec View Source
Specification definitions based around records and utilities.
This serves as the “parent” header file for Cachex, where all records and macros are located. It’s designed as a single inclusion file which provides everything you might need to implement features in Cachex, and indeed when interacting with Cachex.
Most macros in here should be treated as reserved for internal use only, but those based around records can be freely used by consumers of Cachex.
Link to this section Summary
Functions
Creates a cache record from the provided values
Updates a cache record from the provided values
Creates a command record from the provided values
Updates a command record from the provided values
Inserts constant values by a provided key
Creates an entry record from the provided values
Updates an entry record from the provided values
Retrieves the ETS index for an entry field
Generates an ETS modification Tuple for entry field/value pairs
Generates a list of ETS modification Tuples with an updated touch time
Creates an entry record with an updated touch time
Creates an expiration record from the provided values
Updates an expiration record from the provided values
Creates a fallback record from the provided values
Updates a fallback record from the provided values
Creates a hook record from the provided values
Updates a hook record from the provided values
Creates a hooks collection record from the provided values
Updates a hooks record from the provided values
Determines if a value is a negative integer
Determines if a value is a positive integer
Creates a limit record from the provided values
Updates a limit record from the provided values
Generates a named atom for a cache, using the provided service
Checks if a nillable value satisfies a provided condition
Retrieves the current system time in milliseconds
Generates a service call for a cache
Adds a :via delegation to a Keyword List
Creates a warmer record from the provided values
Updates a warmer record from the provided values
Wraps a value inside a tagged Tuple using the provided tag
Link to this section Types
Link to this section Functions
Creates a cache record from the provided values.
A cache record is used to represent the internal state of a cache, and is used when executing calls. Most values in here will be other records defined in the main specification, and as such please see their documentation for further info.
Updates a cache record from the provided values.
Creates a command record from the provided values.
A command is a custom action which can be executed against a cache instance. They
consist of a type (:read
/:write
) and an execution function. The type determines
what form the execution should take.
In the case of a :read
type, an execution function is a simple (any -> any) form,
which will return the returned value directly to the caller. In the case of a :write
type, an execution should be (any -> { any, any }) where the value in the left side
of the returned Tuple will be returned to the caller, and the right side will be set
inside the backing cache table.
Updates a command record from the provided values.
Inserts constant values by a provided key.
Constants are meant to only be used internally as they may change without warning, but they are exposed as part of the spec interface all the same.
Constant blocks can use other constants in their definitions (as it’s all just macros under the hood, and happens at compile time).
Creates an entry record from the provided values.
An entry record reprents a single entry in a cache table.
Each entry has a key/value, along with a touch time and ttl. These records should never be used outside of the Cachex codebase other than when debugging, as they can change at any time and should be regarded as internal only.
Updates an entry record from the provided values.
Retrieves the ETS index for an entry field.
Generates an ETS modification Tuple for entry field/value pairs.
This will convert the entry field name to the ETS index under the hood, and return it inside a Tuple with the provided value.
Generates a list of ETS modification Tuples with an updated touch time.
This will pass the arguments through and behave exactly as entry_mod/1
except that it will automatically update the :touched
field in the entry
to the current time.
Creates an entry record with an updated touch time.
This delegates through to entry/1
, but ensures that the :touched
field is
set to the current time as a millisecond timestamp.
Creates an expiration record from the provided values.
An expiration record contains properties defining expiration policies for a cache.
A default value can be provided which will then be added as a default TTL to all keys which do not have one set explicitly. This must be a valid millisecond integer.
The interval being controlled here is the Janitor service schedule; it controls how often the purge runs in the background of your application to remove expired records. This can be disabled completely by setting the value to nil. This is also a millisecond integer.
The lazy value determines whether or not records can be lazily removed on read. Since this is an expected behaviour it’s enabled by default, but there are cases where you might wish to disable it (such as when consistency isn’t that big an issue).
expiration(expiration(), Keyword.t()) :: expiration()
Updates an expiration record from the provided values.
Creates a fallback record from the provided values.
A fallback can consist of a nillable state to provide to a fallback defintion when requested (via a fallback with an arity of 2). If a default action is provided, it should be a function of arity 1 or 2, depending on if it requires the state or not.
Updates a fallback record from the provided values.
Creates a hook record from the provided values.
Hook records contain the properties needed to start up a hook against a cache instance. There are several components in a hook record:
- arguments to pass through to the hook init/1 callback.
- a flag to set whether or not a hook should fire asynchronously.
- the module name backing the hook, implementing the hook behaviour.
- options to pass to the hook server instance (allowing for names, etc).
- provisions to pass through to the hook provisioning callback.
- a PID reference to a potentially running hook instance (optional).
- the timeout to wait for a response when firing synchronous hooks.
- the type of the hook (whether to fire before/after a request).
These values are mainly provided by the user, and this record might actually be replaced in future with just a behaviour and a set of macros (as this record is very noisy now).
Updates a hook record from the provided values.
Creates a hooks collection record from the provided values.
Hooks records are just a pre-sorted collection of hook records, grouped by their type so that notifications internally do not have to iterate and group manually.
Updates a hooks record from the provided values.
Determines if a value is a negative integer.
Determines if a value is a positive integer.
Creates a limit record from the provided values.
A limit record represents size bounds on a cache, and the way size should be reclaimed.
A limit should have a valid integer as the maximum cache size, which is used to determine when to cull records. By default, an LRW style policy will be applied to remove old records but this can also be customized using the policy value. The amount of space to reclaim at once can be provided using the reclaim option.
You can also specify options to pass through to the policy server, in order to customize policy behaviour.
Updates a limit record from the provided values.
Generates a named atom for a cache, using the provided service.
The list of services is narrowly defined to avoid bloating the atom table as it’s not garbage collected. This macro is only used when naming services.
Checks if a nillable value satisfies a provided condition.
Retrieves the current system time in milliseconds.
Generates a service call for a cache.
This will generate the service name for the provided cache and call
the service with the provided message. The timeout for these service
calls is :infinity
as they’re all able to block the caller.
Adds a :via delegation to a Keyword List.
Creates a warmer record from the provided values.
A warmer record represents cache warmer processes to be run to populate keys.
A warmer should have a valid module provided, which correctly implements the behaviour
associated with Cachex.Warmer
. A state can also be provided, which will be passed
to the execution callback of the provided module (which defaults to nil
).
Updates a warmer record from the provided values.
Wraps a value inside a tagged Tuple using the provided tag.