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);
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.