Gotchas
invalidate([]) is a no-op
Section titled “invalidate([]) is a no-op”An empty prefix matches nothing. Use cache.clear() to wipe everything.
// Use clear() to wipe the entire cachecache.clear()invalidate() is prefix-based, not exact-match
Section titled “invalidate() is prefix-based, not exact-match”A prefix matches every key that starts with it, including nested sub-keys.
// invalidate(['order', 'details', '42']) also matches:// ['order', 'details', '42']// ['order', 'details', '42', 'comments']// ['order', 'details', '42', 'attachments']//// It does NOT match:// ['order', 'details', '43']// ['order', 'list']ref.set() and ref.update() write to the cache
Section titled “ref.set() and ref.update() write to the cache”They update both the Angular resource and the DataCache. Optimistic values
survive cache version bumps from unrelated invalidations. Call invalidate()
to trigger a fresh server fetch.
// set() and update() write to both the Angular resource AND the DataCache.// Optimistic values survive cache version bumps from unrelated invalidations.ref.set(newValue)ref.update(prev => ({ ...prev, name: 'updated' }))
// To trigger a fresh server fetch after an optimistic update:cache.invalidate(['order', 'details', '42'])Cache keys are untyped at the boundary
Section titled “Cache keys are untyped at the boundary”DataCache stores unknown internally. Type correctness depends on consistent
key-to-type pairings in your code.
// Nothing prevents this: both compile finecache.set(['user', '1'], { name: 'Alice' }) // Userconst entry = cache.get<Order[]>(['user', '1']) // reads as Order[]
// Convention: one key prefix per type, enforced in your API service