cache
Generated by tinox doc
tinox.core.cache, bundled with the compiler and also available as a standalone tinox-central package.
Lru cache
import tinox.core.cache
import tinox.core.option
class Main
{
fnc main() -> Int32
{
const 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
const found: Option<Int64> = Cache::get(cache, "a")
println("has a: " + found.isSome().toString())
const value: Option<Int64> = Cache::get(cache, "c")
println("c: " + value.unwrap().toString())
return 0
}
}
class Cache<K, V>
Fields
data | Map<K, V> | |
maxSize | Int64 | |
accessOrder | List<K> |
Methods
fn tinoxLcNew(cap: Int64, ttlMs: Int64) → Int64
fn tinoxLcBegin(h: Int64, key: String) → Int64
fn tinoxLcValue() → String
fn tinoxLcStore(h: Int64, key: String, value: String, token: Int64) → Nothing
fn tinoxLcAbort(h: Int64, key: String) → Nothing
fn tinoxLcEvictAll(h: Int64) → Nothing
fn tinoxLcEvict(h: Int64, key: String) → Nothing
fn tinoxLcStat(h: Int64, which: Int64) → Int64
class LoadingCache
* A bounded, thread-safe, in-process cache from String keys to String values (encode other * types yourself -- the serialization is explicit) with a time-to-live and single-flight loading: * * const cache = LoadingCache::create(500, 30000) // at most 500 entries, 30 s TTL * const price = cache.get("sku-7", key => loadPriceFromDb(key)) * * Concurrent identical misses run the loader ONCE; the other callers wait for that result (at most * TINOX_LC_WAIT_MS, default 60 s, after which a waiter loads on its own and `waitedOut()` counts it). * A loader that throws caches nothing: the error reaches its own caller, the waiters retry (one of * them becomes the next loader). The least recently used entry is dropped when full. evict()/ * evictAll() also invalidate loads in flight: such a load still returns its value to its caller but is * not stored, so a value read before an update never outlives the eviction that followed it. * Memory-only and per process: other instances keep their own copy, so use short TTLs for data * that other writers change.
Fields
handle | Int64 |
Methods
class LruCache<K, V>
Fields
cache | Cache<K, V> |