Skip to content

Commit

Permalink
feat: 新增缓存刷新功能,只要刷新一次缓存,那么之前的相同key的缓存就作废
Browse files Browse the repository at this point in the history
  • Loading branch information
mengxinssfd committed Aug 15, 2022
1 parent e57af60 commit 6a3d604
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/AxiosRequestTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,13 @@ export class AxiosRequestTemplate<CC extends CustomConfig = CustomConfig> {

// 缓存
if (cacheConfig.enable) {
const cache = this.cache.get(requestKey);
if (cache) return cache;
if (cacheConfig.refresh) {
// 只要刷新一次缓存,那么之前的相同key的缓存就作废
this.cache.delete(requestKey);
} else {
const cache = this.cache.get(requestKey);
if (cache) return cache;
}
// 请求
const promise = request();
// 存储缓存
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export interface CustomCacheConfig {
* 是否缓存失败的请求 false时清理
*/
failedReq?: boolean;
/**
* 是否刷新缓存
*/
refresh?: boolean;
}
/**
* @public
Expand Down

0 comments on commit 6a3d604

Please sign in to comment.