Nebulex v1.2.0 Nebulex.Object.Version behaviour View Source
Version handler for cached objects.
The purpose of this module is to allow users implement custom version generator and validator. This interface is used by the adapters to generate and/or validate object versions.
Example
defmodule MyApp.Versioner do
@behaviour Nebulex.Object.Version
def generate(nil), do: 0
def generate(%Object{version: version}) do
version + 1
end
end
If you are going to rely on this feature, it is recommended to use a good version generation algorithm (e.g.: Vector Clocks).
Link to this section Summary
Functions
Validates version conflicts for the given cached object_or_key
.
Callbacks
Generates a new version for the current cached object.
Link to this section Functions
Link to this function
validate(object_or_key, cache, opts)
View Sourcevalidate( object_or_key :: object | Nebulex.Cache.key(), cache :: Nebulex.Cache.t(), opts :: Nebulex.Cache.opts() ) :: {:override | :nothing, object | nil} when object: Nebulex.Object.t()
Validates version conflicts for the given cached object_or_key
.
This function is used by cache's adapters which implement optimistic locking via object's version.
For more information, check out adapters' implementation.
Link to this section Callbacks
Link to this callback
generate(cached_object)
View Sourcegenerate(cached_object :: Nebulex.Object.t()) :: any()
Generates a new version for the current cached object.