Nebulex v2.0.0-rc.0 Nebulex.Adapters.Local.Generation View Source
Generational garbage collection process.
The generational garbage collector manage the heap as several sub-heaps,
known as generations, based on age of the objects. An object is allocated
in the youngest generation, sometimes called the nursery, and is promoted
to an older generation if its lifetime exceeds the threshold of its current
generation (defined by option :gc_interval
). Everytime the GC runs
(triggered by :gc_interval
timeout), a new cache generation is created
and 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 generational garbage collector is attached to it automatically,
therefore, this server MUST NOT be started directly.
Options
These options are configured through the Nebulex.Adapters.Local
adapter:
:gc_interval
- Interval time in milliseconds 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, [])
.:max_size
- Max number of cached entries (cache limit). If it is not set (nil
), the check to release memory is not performed (the default).:allocated_memory
- Max size in bytes allocated for a cache generation. If this option is set and the configured value is reached, a new cache 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_min_timeout
- The min timeout in milliseconds for triggering the next cleanup and memory check. This will be the timeout to use when the max allocated memory is reached. Defaults to30_000
.:gc_cleanup_max_timeout
- The max timeout in milliseconds for triggering the next cleanup and memory check. This is the timeout used when the cache starts or the consumed memory is0
. Defaults to300_000
.
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor.
Flushes the cache (including all its generations).
Returns the list of the generations in the form [newer, older]
.
Returns the memory info in a tuple {used_mem, total_mem}
.
Creates a new cache generation. Once the max number of generations is reached, when a new generation is created, the oldest one is deleted.
Returns the newer generation.
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.
Returns the name of the GC server for the given cache name
.
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
.
Specs
Flushes the cache (including all its generations).
Example
Nebulex.Adapters.Local.Generation.flush(MyCache)
Specs
Returns the list of the generations in the form [newer, older]
.
Example
Nebulex.Adapters.Local.Generation.list(MyCache)
Specs
memory_info(atom()) :: {used_mem :: non_neg_integer(), total_mem :: non_neg_integer()}
Returns the memory info in a tuple {used_mem, total_mem}
.
Example
Nebulex.Adapters.Local.Generation.memory_info(MyCache)
Specs
new(atom(), Nebulex.Cache.opts()) :: [atom()]
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_timer
- Indicates if the poll frequency time-out should be reset or not (default: true).
Example
Nebulex.Adapters.Local.Generation.new(MyCache, reset_timer: :false)
Specs
Returns the newer generation.
Example
Nebulex.Adapters.Local.Generation.newer(MyCache)
Specs
realloc(atom(), 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)
Specs
Returns the name of the GC server for the given cache name
.
Example
Nebulex.Adapters.Local.Generation.server_name(MyCache)
Specs
start_link(Nebulex.Cache.opts()) :: GenServer.on_start()
Starts the garbage collector for the build-in local cache adapter.