View Source Cachex.Policy.LRW (Cachex v3.6.0)
Least recently written eviction policies for Cachex.
This module provides general utilities for implementing an eviction policy for Cachex which will evict the least-recently written entries from the cache. This is determined by the touched time inside each cache record, which means that we don't have to store any additional tables to keep track of access time.
There are several options recognised by this policy which can be passed inside the limit structure when configuring your cache at startup:
The batch size to use when paginating the cache to evict records. This defaults to 100, which is typically going to be fine for most cases, but this option is exposed in case there is need to customize it.
When this policy operates in scheduled mode, this option controls the frequency with which bounds will be checked. This is specified in milliseconds, and will default to once per second (1000). Feel free to tune this based on how strictly you wish to enforce your cache limits.
Sets this policy to enforce bounds reactively. If this option is set to
true, bounds will be checked immediately when a write is made to the cache rather than on a timed schedule. This has the result of being much more accurate with the size of a cache, but has higher overhead due to listening on cache writes.
Setting this to
truewill disable the scheduled checks and thus the
:frequencyoption is ignored in this case.
While the overall behaviour of this policy should always result in the same outcome, the way it operates internally may change. As such, the internals of this module should not be relied upon and should not be considered part of the public API.