Caching README: Update leads Happy Path; cut four nonexistent surfaces
All checks were successful
CultMesh portability and performance / ubuntu-latest reactive semantics and leases (pull_request) Successful in 29m7s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Libby 2026-11-13 14:14:54 +00:00
commit 0e84434a94

View file

@ -131,7 +131,18 @@ using GameCult.Caching;
using GameCult.Caching.MessagePack;
var cache = await CultCacheMessagePack.OpenAsync("Data.msgpack");
var key = new CultRecordKey("potion");
// The golden path: read, change a private copy, commit only if the record is unchanged, re-run on a lost race.
// Durable when it returns; no flush.
var result = cache.Update<ItemData>(key, item =>
{
item ??= new ItemData { Name = "Potion", Sku = "POT-1", Category = "Consumable" };
item.Value += 10;
return item;
});
// The blind opt-out: last writer wins per key.
var handle = await cache.UpsertAsync(new ItemData
{
Name = "Potion",
@ -143,6 +154,10 @@ var handle = await cache.UpsertAsync(new ItemData
await cache.FlushAsync();
```
`Update` may run your function more than once, so it must have no side effects. Returning null writes nothing, and a
lost race that outlasts `maxAttempts` comes back as `CultUpdateOutcome.LostRace`. `UpsertAsync` plus `FlushAsync` never
checks what it overwrites.
If you want the explicit assembly rite, the lower-level `CultCache` +
`SingleFileMessagePackBackingStore` path is still there. The helper is just the
blessed front door.
@ -294,13 +309,10 @@ Useful surfaces:
- `cache.IsDirty`
- `store.IsDirty`
- `cache.Document<T>(key)`
- `cache.Soa<T>()`
- `cache.UpsertAsync(document)`
- `cache.Update<T>(key, apply)`
- `cache.UpsertAsync(document)` (blind write)
- `cache.FlushAllBackingStores()`
- `cache.FlushAsync()`
- `cache.FlushBackingStore(store)`
- `cache.PrepareForReloadOrShutdown()`
- `cache.PrepareForReloadOrShutdownAsync()`
- `cache.FlushAttachedStoresOnDispose`
- `store.FlushOnDispose`