cache

Generated by tinox doc

An in-process, fixed-size LRU cache: Cache<K, V> evicts the least-recently-used entry once maxSize is reached; LruCache<K, V> is a thin wrapper around it. Purely in-memory -- for a cache shared across processes/workers, see tinox.core.redis instead.

ModuleVersionGroup
option1.0.0tinox.core

Lru cache

import tinox.core.cache;
import tinox.core.option;

class Main
{
    fnc main() -> Int32
    {
        let cache: Cache<String, Int64> = Cache::new(2);
        Cache::set(cache, "a", 1);
        Cache::set(cache, "b", 2);
        Cache::set(cache, "c", 3); // evicts "a", the least-recently-used entry

        let found: Option<Int64> = Cache::get(cache, "a");
        println("has a: " + found.isSome().toString());

        let value: Option<Int64> = Cache::get(cache, "c");
        println("c: " + value.unwrap().toString());
        return 0;
    }
}