|
| 1 | +# Invalidation |
| 2 | + |
| 3 | +`nova_cache` ships cluster invalidation as a swappable transport behaviour. |
| 4 | +The default transport is `nova_cache_invalidator_pg`, built on `pg`. |
| 5 | + |
| 6 | +## Guarantee |
| 7 | + |
| 8 | +**Best-effort eventual.** TTL is the correctness backstop. A node that is |
| 9 | +netsplit, GC-paused, or just-joined may miss broadcasts and serve stale data |
| 10 | +until the row expires. |
| 11 | + |
| 12 | +## Per-cache mode |
| 13 | + |
| 14 | +Configured via the `invalidation` key in the cache spec: |
| 15 | + |
| 16 | +| Mode | Behaviour | |
| 17 | +| ------------- | ------------------------------------------------------------------------ | |
| 18 | +| `best_effort` | Subscribe to broadcasts; serve stale on miss. Default. | |
| 19 | +| `ttl_only` | Skip broadcasts entirely; rely solely on TTL. | |
| 20 | +| `strict` | Best-effort plus refuses to start without `ttl_default`. Bounds staleness.| |
| 21 | + |
| 22 | +## Failure mode: a node misses a broadcast |
| 23 | + |
| 24 | +It serves stale data until the row's TTL elapses. If the row was written with |
| 25 | +`ttl => infinity`, it serves stale data indefinitely. This is the design. |
| 26 | + |
| 27 | +For workloads where "indefinitely stale" is unacceptable, use `strict` mode |
| 28 | +and a finite `ttl_default`. |
| 29 | + |
| 30 | +## Failure mode: a node joins late |
| 31 | + |
| 32 | +On join, the node's caches start empty. They subscribe and start receiving |
| 33 | +broadcasts immediately. There is no backfill of historical events. Existing |
| 34 | +entries on the joining node (e.g. after a netsplit heal) are not purged |
| 35 | +automatically in `best_effort` mode -- if you need that, run `clear/1` from |
| 36 | +your application's join handler. |
| 37 | + |
| 38 | +## Writing a new transport |
| 39 | + |
| 40 | +1. `-behaviour(nova_cache_invalidator).` |
| 41 | +2. Implement `start_link/1`, `subscribe/2`, `broadcast/2`. |
| 42 | +3. Deliver event payloads to subscribed handlers on every node. |
| 43 | +4. Set `{nova_cache, [{invalidator, your_module}]}` in `sys.config`. |
| 44 | + |
| 45 | +Transports must deliver events unchanged. They may drop events on failure |
| 46 | +without compromising correctness, because TTL is the backstop. |
0 commit comments