View Source Cachex.Disk (Cachex v3.6.0)

Module dedicated to basic filesystem iteractions.

This module contains the required interactions with a filesystem for serializing terms directly to a given file path. This is mainly used by the backup/restore feature of a cache in order to provide easy export functionality.

The behaviours in here are general enough that they can be used for various use cases rather than just cache serialization, and compression can also be controlled.

Link to this section Summary

Functions

Reads a file from a filesystem using the Erlang Term Format.

Writes a value to a filesystem using the Erlang Term Format.

Link to this section Functions

Link to this function

read(path, options \\ [])

View Source
@spec read(binary(), Keyword.t()) :: {:ok, any()} | {:error, atom()}

Reads a file from a filesystem using the Erlang Term Format.

If there's an error reading the file, or the file is invalid ETF, an error will be returned. Otherwise a Tuple containing the terms will be returned.

As we can't be certain what we're reading from the file, we make sure to load it safely to avoid malicious content (although the chance of that is slim).

Link to this function

write(value, path, options \\ [])

View Source
@spec write(any(), binary(), Keyword.t()) :: {:ok, true} | {:error, atom()}

Writes a value to a filesystem using the Erlang Term Format.

The compression can be controlled using the :compression option in order to reduce the size of the output. By default this value will be set to level 1 compression. If set to 0, compression will be disabled but be aware storage will increase dramatically.