Stdlib index
- Captured-borrow migration worklist (3.3.3)
- Owned-bind migration worklist (8.2.7)
- Return-side title audit — the ride-through enumeration
- stdlib ownership audit
- stdlib ownership dispositions (plan 1.3.1 / 4.3.1)
codec
codec / csv
codec / json
collection
- ArrayList
- BPlusTree
- Cache
- Collectors
- HashMap
- HashSet
- Heap
- ImmutableList
- ImmutableMap
- ImmutableSet
- LinkedList
- RedBlackTree
- Sort
collection / ltm
concurrent
error
gfx
hash
ifx
io
io / file
io / net
io / net / dns
io / net / tls
io / net / uri
lang
lang / stream
math
math / fft
math / linalg
math / npio
math / poly
math / random
math / stats
nucleo
- Columns — the Arrow-laid-out substrate
- Fused tensor expressions — Fuse
- Table — the lazy, typed dataframe
- Tape — define-by-run autograd
- Transform intrinsics — Grad, Vmap, Jit
process
reflect
search / distance
search / fuzzy
search / ngram
session
time
- Clock
- DateTimeFormatter
- Duration
- Instant
- LocalDate
- LocalDateTime
- LocalTime
- Period
- ZonedDateTime
- ZoneId
- ZoneOffset
wire
xpu
xpu / mesh
Cache<K, V>
cajeta.collection.Cache — bounded in-memory cache with LRU eviction and
optional TTL. get / put / remove / containsKey are amortized O(1)
(one hashmap lookup plus a doubly-linked-list pointer reshuffle); put
inserts at the MRU head and evicts the LRU tail when over maxEntries.
setMaxAge arms time-based expiration: an expired entry misses on lookup
even if still physically present, and evict() drains everything expired.
Not thread-safe — wrap in a lock when instances are shared.
Cache<int64, String> cache = heap Cache<int64, String>(1024);
cache.setMaxAge(Duration.ofSeconds(30));
cache.put(42, "answer");
Optional<String> hit = cache.get(42);
if (hit.isPresent()) {
String v = hit.get();
}
Methods
| Signature | |
|---|---|
Cache(int32 maxEntries) ⚑ | Build a cache with the given LRU bound |
void setMaxAge(Duration maxAge) | Set the maximum age before an entry expires; 0 (the default) disables TTL |
int32 count() | Live entry count |
boolean isEmpty() | count() == 0 |
boolean containsKey(K key) | True when key is present AND not expired |
Optional<V> get(K key) | Look up key; present hit is promoted to most-recently-used |
void put(K key, V value) | Insert (or replace) key’s value; pass #key if you want the cache to take title |
void remove(K key) | Drop key and its LRU node if present; a no-op otherwise |
void clear() | Drop every entry and reset the LRU list to empty |
void evict() | Manual eviction pass — drops everything currently expired under the TTL |
⚑ = @EntryPoint
See also
- Source:
runtime/src/cajeta/collection/Cache.cajeta - HashMap — the backing key index
- Optional —
get’s hit/miss result - Duration — the TTL argument