Plugins
Throttle
Limit request frequency
The throttle plugin limits how often a request can be made. Extra requests immediately return cached data instead of hitting the network.
Installation
npm install @spoosh/plugin-throttleUsage
import { throttlePlugin } from "@spoosh/plugin-throttle";
const plugins = [
// Register at end to block even force fetches
throttlePlugin(),
];
// Max 1 request per second - extras return cached data
const { data } = useRead(
(api) => api.expensive.$get(),
{ throttle: 1000 }
);Options
Per-Request Options
| Option | Type | Description |
|---|---|---|
throttle | number | Max 1 request per X milliseconds. Extra requests return cached data. |
Throttle vs Debounce
| Throttle | Debounce | |
|---|---|---|
| First request | Executes immediately | Waits for delay |
| Extra requests | Returns cached data | Resets the delay timer |
| Use case | Rate-limiting expensive endpoints | Waiting for input to stop |
Plugin Order
Register the throttle plugin at the end of your plugin list to ensure it blocks all requests, including force fetches:
const plugins = [
cachePlugin({ staleTime: 5000 }),
deduplicationPlugin(),
invalidationPlugin(),
retryPlugin(),
throttlePlugin(), // Last - blocks everything
];