Show HN: CasCache – multi-generational cache with optimistic concurrency control

https://news.ycombinator.com/rss Hits: 6
Summary

cascache Provider-agnostic CAS (Compare-And-Set) cache with pluggable codecs and a pluggable generation store. Safe single-key reads (no stale values), optional bulk caching with read-side validation, and an opt‑in distributed mode for multi-replica deployments. Contents Overview CAS safety: Writers snapshot a per-key generation before the DB read. Cache writes commit only if the generation is unchanged. Writers snapshot a per-key before the DB read. Cache writes commit only if the generation is unchanged. Singles: Never return stale values; corrupt/type-mismatched entries self-heal. Never return stale values; corrupt/type-mismatched entries self-heal. Bulk: Cache a set-shaped result. On read, validate every member’s generation. Reject the bulk if any member is stale. Cache a set-shaped result. On read, validate every member’s generation. Reject the bulk if any member is stale. Composable: Plug any value provider (Ristretto/BigCache/Redis) and any codec (JSON/Msgpack/CBOR/Proto). Plug any value provider (Ristretto/BigCache/Redis) and any codec (JSON/Msgpack/CBOR/Proto). Distributed Keep local generations (default) or plug a shared GenStore (e.g., Redis) for cross-replica correctness and warm restarts. Read path (single) Get(k) │ provider.Get("single:<ns>:"+k) ───► [wire.DecodeSingle] │ gen == currentGen("single:<ns>:"+k) ? │ yes no ▼ ┌───────────────┐ codec.Decode(payload) │ Del(entry) │ │ │ return miss │ return v └───────────────┘ Write path (single, CAS) obs := SnapshotGen(k) // BEFORE DB read v := DB.Read(k) SetWithGen(k, v, obs) // write iff currentGen(k) == obs Bulk read validation GetBulk(keys) -> provider.Get("bulk:<ns>:hash(sorted(keys))") Decode -> [(key,gen,payload)]*n for each item: gen == currentGen("single:<ns>:"+key) ? if all valid -> decode all, return else -> drop bulk, fall back to singles Quick start import ( "context" "time" "github.com/unkn0wn-root/cascache" rp "github.com/unkn0wn-root/cascache/provider/ristretto" ) type User struct { ID , Name s...

First seen: 2025-08-25 09:13

Last seen: 2025-08-25 14:14