CacheLRU

CacheLRU contains maximum size items Eviction policy: 1. evict TTL-ed entry (if TTL enabled), otherwise 2. if oldest entry not expired - evict oldes accessed (LRU)

User can be informed about evicted entries via cache event list.

Members

Functions

cacheEvents
auto cacheEvents()
Undocumented in source. Be warned that the author may not have intended to support it.
clear
void clear()
Undocumented in source. Be warned that the author may not have intended to support it.
enableCacheEvents
auto enableCacheEvents()
Undocumented in source. Be warned that the author may not have intended to support it.
get
Nullable!V get(K k)
Undocumented in source. Be warned that the author may not have intended to support it.
length
size_t length()
Undocumented in source. Be warned that the author may not have intended to support it.
put
PutResult put(K k, V v)
Undocumented in source.
remove
bool remove(K k)
Undocumented in source. Be warned that the author may not have intended to support it.
size
auto size(size_t s)
Undocumented in source. Be warned that the author may not have intended to support it.
size
size_t size()
Undocumented in source. Be warned that the author may not have intended to support it.
ttl
auto ttl(uint d)
Undocumented in source. Be warned that the author may not have intended to support it.
ttl
uint ttl()
Undocumented in source. Be warned that the author may not have intended to support it.

Structs

CacheEventRange
struct CacheEventRange(K, V)
Undocumented in source.

Examples

import std.experimental.allocator.mallocator;

alias allocator = Mallocator.instance;
alias Cache = CacheLRU!(int, string);

auto lru = make!(Cache)(allocator);

lru.size = 2048; // keep 2048 elements in cache
lru.ttl = 60; // set 60 seconds TTL for items in cache

lru.put(1, "one");
auto v = lru.get(0);
assert(v.isNull); // no such item in cache
v = lru.get(1);
assert(v == "one"); // 1 is in cache
lru.remove(1);

Meta