Cache2Q

Constructors

this
this()
Undocumented in source.
this
this(int s)
Undocumented in source.

Members

Functions

cacheEvents
auto cacheEvents()
clear
void clear()

Drop all elements from cache.

enableCacheEvents
auto enableCacheEvents()
get
Nullable!V get(K k)

Get element from cache.

length
int length()

Number of elements in cache.

put
PutResult put(K k, V v, TTL ttl)

Put element to cache.

remove
bool remove(K k)

Remove element from cache.

size
auto size(uint s)

Set total cache size. 'In' and 'Out' gets 1/6 of total size, Main gets 2/3 of size.

sizeIn
auto sizeIn(uint s)

Set In queue size

sizeMain
auto sizeMain(uint s)

Set Main queue size

sizeOut
auto sizeOut(uint s)

Set Out queue size

ttl
void ttl(Duration v)

Set default ttl (seconds)

ttl
deprecated void ttl(int v)
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

// create cache with total size 1024
auto allocator = Mallocator.instance;
auto cache = () @trusted {
    return allocator.make!(Cache2Q!(int, string))(1024);
}();
() @safe @nogc nothrow {
    cache.sizeIn = 10; // if you need, later you can set any size for In queue
    cache.sizeOut = 55; // and for out quque
    cache.sizeMain = 600; // and for main cache
    cache.put(1, "one");
    assert(cache.get(1) == "one"); // key 1 is in cache
    assert(cache.get(2).isNull); // key 2 not in cache
    assert(cache.length == 1); // # of elements in cache
    cache.clear; // clear cache
}();
dispose(allocator, cache);

Meta