Skip to content

Commit

Permalink
feat: getcache support params (#1395)
Browse files Browse the repository at this point in the history
  • Loading branch information
baranwang authored Dec 21, 2021
1 parent fe16571 commit 5b5e3b6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions packages/hooks/src/useRequest/src/plugins/useCachePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ const useCachePlugin: Plugin<any, any[]> = (
cacheSubscribe.trigger(key, cachedData.data);
};

const _getCache = (key: string) => {
const _getCache = (key: string, params: any[] = []) => {
if (customGetCache) {
return customGetCache();
return customGetCache(params);
}
return cache.getCache(key);
};
Expand Down Expand Up @@ -64,8 +64,8 @@ const useCachePlugin: Plugin<any, any[]> = (
}

return {
onBefore: () => {
const cacheData = _getCache(cacheKey);
onBefore: (params) => {
const cacheData = _getCache(cacheKey, params);

if (!cacheData || !Object.hasOwnProperty.call(cacheData, 'data')) {
return {};
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/src/useRequest/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export interface Options<TData, TParams extends any[]> {
cacheTime?: number;
staleTime?: number;
setCache?: (data: CachedData<TData, TParams>) => void;
getCache?: () => CachedData<TData, TParams> | undefined;
getCache?: (params: TParams) => CachedData<TData, TParams> | undefined;

// retry
retryCount?: number;
Expand Down

0 comments on commit 5b5e3b6

Please sign in to comment.