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

OptionTypeDefault
throttlenumber1000
methodsstring[]['GET']
key(url, init) => stringmethod + url
invalidateOnMutationbooleantrue

When invalidateOnMutation is enabled, any POST, PUT, PATCH, or DELETE request clears the entire cache so subsequent GETs fetch fresh data.