Cache Middleware
Throttle GET requests by serving cached responses within a TTL window
Basic Usage
import { throttlingCache } from '@cleverbrush/client/cache';
const client = createClient(api, {
middlewares: [throttlingCache({ throttle: 5000 })],
});
// First call hits the network
await client.todos.list();
// Within 5 seconds — returns cached response instantly
await client.todos.list();Options
| Option | Type | Default |
|---|---|---|
throttle | number | 1000 |
methods | string[] | ['GET'] |
key | (url, init) => string | method + url |
invalidateOnMutation | boolean | true |
When invalidateOnMutation is enabled, any POST, PUT, PATCH, or DELETE request clears the entire cache so subsequent GETs fetch fresh data.