BoundedExpiringMap

A string-keyed cache of V with a per-entry insertion/activity timestamp, bounded by an idle TTL and a maximum live-entry count. It owns the value map and the parallel timestamp map together so the "remove from both" invariant lives in one place, and runs the TTL sweep + LRU cap eviction internally.

ttl == Duration.zero disables the sweep; maxEntries == 0 disables the cap. clock is injectable (null => MonoTime.currTime) so callers can drive expiry deterministically in tests. The container does no locking; the owner serializes access (e.g. synchronized on a synchronized-using class, or vibe.d's single-fiber loop).

Members

Functions

contains
bool contains(string key)

Whether key has a live entry. Sweeps expired entries first so that a session past its idle TTL is not reported as present.

get
V* get(string key, bool refresh)

Pointer to the live value for key, or null when absent. Sweeps expired entries before the lookup so a session past its idle TTL is not returned. When refresh is set, a hit stamps the entry as just-active so it survives future idle sweeps.

length
size_t length()

Number of live entries.

put
void put(string key, V value)

Sweep expired entries, evict the oldest if inserting a new key would exceed the cap, then store value and stamp it as just-active.

remove
bool remove(string key)

Remove the entry for key from both maps. Returns whether it existed.

take
V take(string key, bool found)

Sweep expired entries, then consume and return the entry for key, setting found. The entry is removed (single use).