View Source ttl_map (util v1.3.3)
Map with TTL key/value eviction.
An insert of a Key/Value pair in the map will store the timestamp of the maybe_add. Additionally a queue of maybe_adds is maintained by this container, which is checked on each insert and the expired Key/Value pairs are evicted from the map.Link to this section Summary
Functions
Evict stale items from the map given the current timestamp
Now
.Evict stale items (up to the
Limit
) from the map given the current timestamp Now
.Create a new map with a given TTL time for inserted items
Create a new map with a given TTL time for inserted items.
Opts
is a list of options:- name
- The name of the ETS table (defaults to
undefined
) - access
- The access level of the ETS table (defaults to
private
)
Get the current timestamp in microseconds since Unix epoch.
Get the number of items in the map.
Try to add a
Key/Value
pair to the map. If more than TTL time elapsed since the last insert of the Key
or the Key
is not found in the map, the value is inserted, otherwise no insertion is made.Link to this section Types
-type ttl_map() :: #ttl_map{}.
Link to this section Functions
Now
.
Limit
) from the map given the current timestamp Now
.
Opts
is a list of options:- name
- The name of the ETS table (defaults to
undefined
) - access
- The access level of the ETS table (defaults to
private
)
-spec now() -> non_neg_integer().
-spec size(ttl_map()) -> non_neg_integer().
Key/Value
pair to the map. If more than TTL time elapsed since the last insert of the Key
or the Key
is not found in the map, the value is inserted, otherwise no insertion is made.