mirror of
https://github.com/ershisan99/podcaster.git
synced 2026-01-24 12:35:10 +00:00
feat: add idb persister to cache requests for 24 hours
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { get, set, del } from "idb-keyval";
|
||||
import {
|
||||
PersistedClient,
|
||||
Persister,
|
||||
} from "@tanstack/react-query-persist-client";
|
||||
/**
|
||||
* Creates an Indexed DB persister
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API
|
||||
*/
|
||||
export function createIDBPersister(idbValidKey: IDBValidKey = "reactQuery") {
|
||||
return {
|
||||
persistClient: async (client: PersistedClient) => {
|
||||
await set(idbValidKey, client);
|
||||
},
|
||||
restoreClient: async () => {
|
||||
return await get<PersistedClient>(idbValidKey);
|
||||
},
|
||||
removeClient: async () => {
|
||||
await del(idbValidKey);
|
||||
},
|
||||
} as Persister;
|
||||
}
|
||||
Reference in New Issue
Block a user