@spoosh/plugin-cache
v0.2.2
Published
Response caching plugin for Spoosh with configurable stale time
Maintainers
Readme
@spoosh/plugin-cache
Response caching plugin for Spoosh with configurable stale time.
Documentation · Requirements: TypeScript >= 5.0 · Peer Dependencies: @spoosh/core
Installation
npm install @spoosh/plugin-cacheUsage
import { Spoosh } from "@spoosh/core";
import { cachePlugin } from "@spoosh/plugin-cache";
const client = new Spoosh<ApiSchema, Error>("/api").use([
cachePlugin({ staleTime: 5000 }),
]);
// Per-query override
useRead((api) => api("posts").GET(), { staleTime: 10000 });Options
Plugin Config
| Option | Type | Default | Description |
| ----------- | -------- | ------- | ---------------------------------- |
| staleTime | number | 0 | Default stale time in milliseconds |
Per-Request Options
| Option | Type | Description |
| ----------- | -------- | ------------------------------------ |
| staleTime | number | Override stale time for this request |
Instance API
The plugin exposes a clearCache function for manually clearing all cached data:
import { createReactSpoosh } from "@spoosh/react";
const { useRead, clearCache } = createReactSpoosh(client);
// Clear all cached data (e.g., on logout or user switch)
function handleLogout() {
clearCache();
}| Method | Description |
| ------------ | -------------------------------------------------------- |
| clearCache | Clears all cached data. Useful for logout/user switching |
