English | 简体中文
Repeated request optimization Based on axios cache policy, duplicate requests are handled. In principle, the same concurrent request is cached. There will be only one request, and other requests will directly return the results, reducing server pressure, reducing unnecessary requests, and improving performance.pnpm install axios-cache-helper
- useOptimizationCache It is an initialization configuration method that uses default configuration when not calling or passing values
- ignoreRequest Ignore the request address, do not cache it, support strings or regularization such as
/getOrder
- throttlingTime Repeat request interval time, default 200ms
import { useOptimizationCache } from 'axios-cache-helper';
const {
optimizationCacheErrorsRes,
optimizationCacheReq,
optimizationCacheSuccessRes,
} = useOptimizationCache();
// OR
const {
optimizationCacheErrorsRes,
optimizationCacheReq,
optimizationCacheSuccessRes,
} = useOptimizationCache({
throttlingTime: 200,
ignoreRequest: [/getOrder/, '/getorder/search'],
});
import {
optimizationCacheErrorsRes,
optimizationCacheReq,
optimizationCacheSuccessRes,
useOptimizationCache,
} from 'axios-cache-helper';
useOptimizationCache();
// OR
useOptimizationCache({ throttlingTime: 200, ignoreRequest: [] });
// Configure axios request configuration in the request interceptor
await optimizationCacheReq(config);
// Successful response axios configuration in response interceptor
optimizationCacheSuccessRes(response);
// Failed response axios configuration in response interceptor
optimizationCacheErrorsRes(error);