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 new(maxSize: Int64) → Cache<K, V>
fn get(cache: Cache<K, V>, key: K) → Option<V>
fn set(cache: Cache<K, V>, key: K, value: V) → Nothing
fn remove(cache: Cache<K, V>, key: K) → Bool
fn clear(cache: Cache<K, V>) → Nothing
fn touch(cache: Cache<K, V>, key: K) → Nothing
class LruCache<K, V>
Fields
cache | Cache<K, V> |
Methods
fn new(maxSize: Int64) → LruCache<K, V>
fn get(cache: LruCache<K, V>, key: K) → Option<V>
fn set(cache: LruCache<K, V>, key: K, value: V) → Nothing