diff --git a/docs/src/guide/storages.md b/docs/src/guide/storages.md index 0366720..15a059d 100644 --- a/docs/src/guide/storages.md +++ b/docs/src/guide/storages.md @@ -38,7 +38,10 @@ For long running processes, you can avoid memory leaks by using playing with the ```ts import Axios from 'axios'; -import { setupCache, buildMemoryStorage } from 'axios-cache-interceptor'; +import { + setupCache, + buildMemoryStorage +} from 'axios-cache-interceptor'; setupCache(axios, { // You don't need to to that, as it is the default option. @@ -140,7 +143,8 @@ simple object to build the storage. It has 3 methods: storage or `undefined` if not found. - `clear() => MaybePromise`: - Clears all data from storage. + Clears all data from storage. **This method isn't used by the interceptor itself**, instead, its + here for you to use it programmatically. ## Third Party Storages @@ -240,7 +244,7 @@ const indexedDbStorage = buildStorage({ ### Node Cache -This example implementation uses [node-cache](https://github.com/node-cache/node-cache) as a storage method. Do note +This example implementation uses [node-cache](https://github.com/node-cache/node-cache) as a storage method. Do note that this library is somewhat old, however it appears to work at the time of writing. ```ts diff --git a/src/storage/build.ts b/src/storage/build.ts index b599ee2..a3a47c0 100644 --- a/src/storage/build.ts +++ b/src/storage/build.ts @@ -1,13 +1,20 @@ import type { CacheRequestConfig } from '../cache/axios.js'; import { Header } from '../header/headers.js'; import type { MaybePromise } from '../util/types.js'; -import type { AxiosStorage, CachedStorageValue, StaleStorageValue, StorageValue } from './types.js'; +import type { + AxiosStorage, + CachedStorageValue, + StaleStorageValue, + StorageValue +} from './types.js'; /** Returns true if the provided object was created from {@link buildStorage} function. */ export const isStorage = (obj: unknown): obj is AxiosStorage => !!obj && !!(obj as Record)['is-storage']; -function hasUniqueIdentifierHeader(value: CachedStorageValue | StaleStorageValue): boolean { +function hasUniqueIdentifierHeader( + value: CachedStorageValue | StaleStorageValue +): boolean { const headers = value.data.headers; return ( @@ -65,13 +72,6 @@ export interface BuildStorage extends Omit { key: string, currentRequest?: CacheRequestConfig ) => MaybePromise; - - /** - * Deletes all values from the storage. - * - * @see https://axios-cache-interceptor.js.org/guide/storages#buildstorage - */ - clear: () => MaybePromise; } /** diff --git a/src/storage/types.ts b/src/storage/types.ts index e478336..1f3c3ce 100644 --- a/src/storage/types.ts +++ b/src/storage/types.ts @@ -136,9 +136,12 @@ export interface AxiosStorage { get: (key: string, currentRequest?: CacheRequestConfig) => MaybePromise; /** - * Deletes all values from the storage. + * Deletes all values from the storage, this method isn't used by the interceptor + * and is here just for convenience. + * + * **All native storages implement them, but it's not required.** * * @see https://axios-cache-interceptor.js.org/guide/storages#buildstorage */ - clear: () => MaybePromise; + clear?: () => MaybePromise; }