Nebulex v1.2.0 Nebulex.Adapters.Local.Generation View Source

Generations Handler. This GenServer acts as garbage collector, everytime it runs, a new cache generation is created a the oldest one is deleted.

The only way to create new generations is through this module (this server is the metadata owner) calling new/2 function. When a Cache is created, a generations handler associated to that Cache is started at the same time, therefore, this server MUST NOT be started directly.

Options

These options are configured via the built-in local adapter (Nebulex.Adapters.Local):

  • :gc_interval - Interval time in seconds to garbage collection to run, delete the oldest generation and create a new one. If this option is not set, garbage collection is never executed, so new generations must be created explicitly, e.g.: new(cache, []).

  • :allocated_memory - Max size in bytes allocated for a cache generation. If this option is set and the configured value is reached, a new generation is created so the oldest is deleted and force releasing memory space. If it is not set (nil), the cleanup check to release memory is not performed (the default).

  • :gc_cleanup_interval - The number of writes needed to run the cleanup check. Once this value is reached and only if allocated_memory option is set, the cleanup check is performed. Defaults to 10, so after 10 write operations the cleanup check is performed.

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Triggers the cleanup process to check whether or not the max generation size has been reached. If so, a new generation is pushed in order to release memory and keep it within the configured limit.

Flushes the cache (including all its generations).

Returns the GenServer state (mostly for testing purposes).

Creates a new cache generation. Once the max number of generations is reached, when a new generation is created, the oldest one is deleted.

Reallocates the block of memory that was previously allocated for the given cache with the new size. In other words, reallocates the max memory size for a cache generation.

Starts the garbage collector for the build-in local cache adapter.

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Triggers the cleanup process to check whether or not the max generation size has been reached. If so, a new generation is pushed in order to release memory and keep it within the configured limit.

Example

Nebulex.Adapters.Local.Generation.cleanup(MyCache)

Flushes the cache (including all its generations).

Example

Nebulex.Adapters.Local.Generation.flush(MyCache)
Link to this function

get_state(cache)

View Source
get_state(Nebulex.Cache.t()) :: Nebulex.Adapters.Local.Generation.State.t()

Returns the GenServer state (mostly for testing purposes).

Example

Nebulex.Adapters.Local.Generation.get_state(MyCache)

Creates a new cache generation. Once the max number of generations is reached, when a new generation is created, the oldest one is deleted.

Options

  • :reset_timeout - Indicates if the poll frequency time-out should be reset or not (default: true).

Example

Nebulex.Adapters.Local.Generation.new(MyCache, reset_timeout: :false)
Link to this function

realloc(cache, size)

View Source
realloc(Nebulex.Cache.t(), pos_integer()) :: :ok

Reallocates the block of memory that was previously allocated for the given cache with the new size. In other words, reallocates the max memory size for a cache generation.

Example

Nebulex.Adapters.Local.Generation.realloc(MyCache, 1_000_000)

Starts the garbage collector for the build-in local cache adapter.