View Source Nebulex.Adapter.Persistence behaviour (Nebulex v2.4.1)

Specifies the adapter persistence API.

default-implementation

Default implementation

This module provides a default implementation that uses File and Stream under-the-hood. For dumping a cache to a file, the entries are streamed from the cache and written in chunks (one chunk per line), and each chunk contains N number of entries. For loading the entries from a file, the file is read and streamed line-by-line, so that the entries collected on each line are inserted in streaming fashion as well.

The default implementation accepts the following options only for dump operation (there are not options for load):

  • entries_per_line - The number of entries to be written per line in the file. Defaults to 10.

  • compression - The compression level. The values are the same as :erlang.term_to_binary /2. Defaults to 6.

See Nebulex.Cache.dump/2 and Nebulex.Cache.load/2 for more information.

Link to this section Summary

Callbacks

Dumps a cache to the given file path.

Loads a dumped cache from the given path.

Link to this section Callbacks

Link to this callback

dump(adapter_meta, t, opts)

View Source
@callback dump(Nebulex.Adapter.adapter_meta(), Path.t(), Nebulex.Cache.opts()) ::
  :ok | {:error, term()}

Dumps a cache to the given file path.

Returns :ok if successful, or {:error, reason} if an error occurs.

See Nebulex.Cache.dump/2.

Link to this callback

load(adapter_meta, t, opts)

View Source
@callback load(Nebulex.Adapter.adapter_meta(), Path.t(), Nebulex.Cache.opts()) ::
  :ok | {:error, term()}

Loads a dumped cache from the given path.

Returns :ok if successful, or {:error, reason} if an error occurs.

See Nebulex.Cache.load/2.