Skip to content

Commit

Permalink
feat: add clear method to cache object
Browse files Browse the repository at this point in the history
  • Loading branch information
shhonarmandi committed May 2, 2024
1 parent 6da84a3 commit 133d5ad
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/_internal/types.ts
Expand Up @@ -514,6 +514,7 @@ export interface Cache<Data = any> {
get(key: string): State<Data> | undefined
set(key: string, value: State<Data>): void
delete(key: string): void
clear(): void
}

export interface StateDependencies {
Expand Down
7 changes: 4 additions & 3 deletions test/use-swr-cache.test.tsx
Expand Up @@ -252,16 +252,17 @@ describe('useSWR - cache provider', () => {
parentCache = parentCache_
return {
keys: () => parentCache.keys(),
set: (k, v) => parentCache_.set(k, v),
set: (k, v) => parentCache.set(k, v),
get: k => {
// We append `-extended` to the value returned by the parent cache.
const v = parentCache_.get(k)
const v = parentCache.get(k)
if (v && typeof v.data !== 'undefined') {
return { ...v, data: v.data + '-extended' }
}
return v
},
delete: k => parentCache_.delete(k)
delete: k => parentCache.delete(k),
clear: () => parentCache.clear()
}
}
})
Expand Down

0 comments on commit 133d5ad

Please sign in to comment.