From 133d5ad82a1886f0d9e6190c96615954999ca333 Mon Sep 17 00:00:00 2001 From: Mohsen Honarmandi Date: Thu, 2 May 2024 12:19:42 +0330 Subject: [PATCH] feat: add clear method to cache object --- src/_internal/types.ts | 1 + test/use-swr-cache.test.tsx | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/_internal/types.ts b/src/_internal/types.ts index 528dae9327..c8dfe51f6c 100644 --- a/src/_internal/types.ts +++ b/src/_internal/types.ts @@ -514,6 +514,7 @@ export interface Cache { get(key: string): State | undefined set(key: string, value: State): void delete(key: string): void + clear(): void } export interface StateDependencies { diff --git a/test/use-swr-cache.test.tsx b/test/use-swr-cache.test.tsx index 20466383b7..73e641f404 100644 --- a/test/use-swr-cache.test.tsx +++ b/test/use-swr-cache.test.tsx @@ -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() } } })