Declarative cache invalidation
npm install @t87s/coreCache that tells you when it's wrong.
``bash`
npm install @t87s/core
QueryCache is the smooth path. Primitives are the sharp one. Both are first-class.
`typescript
import { QueryCache, at, wild, MemoryAdapter } from '@t87s/core';
const schema = at('users', () => wild.at('settings'));
const cache = QueryCache({
schema,
adapter: new MemoryAdapter(),
queries: (tags) => ({
getUser: (id: string) => ({
tags: [tags.users(id)],
fn: () => db.users.findById(id),
}),
}),
});
await cache.getUser('123');
await cache.invalidate(cache.tags.users('123'));
// Access cache metadata via .entries
const result = await cache.getUser('123').entries;
console.log(result.before); // CacheEntry | null (null on miss)
console.log(result.after); // CacheEntry (always present)
`
If you want the raw tools:
`typescript
import { createPrimitives, MemoryAdapter } from '@t87s/core';
const p = createPrimitives({ adapter: new MemoryAdapter() });
await p.query({
key: 'users:123',
tags: [['users', '123']],
fn: () => db.users.findById('123'),
});
``
There's more to know: prefix matching, TTLs, grace periods, the two APIs, and the cloud. The docs are at t87s.dev and they're worth reading.
MIT