Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | 157x 157x 130x 130x 4x 126x | import { createCache, validateOptions } from "./cache";
import { persistentStorage } from "./persistent";
import { sessionStorageBackend } from "./session";
import type { CacheOptions, ResourceCache, SessionCacheOptions } from "./types";
export type {
CacheGetOptions,
CacheOptions,
CacheSnapshot,
CacheValidation,
LoadResult,
ResourceCache,
SessionCacheOptions,
} from "./types";
/** Create an IndexedDB cache. Storage failures preserve successful network results. */
export function createPersistentCache<T, Q>(options: CacheOptions<T, Q>): ResourceCache<T, Q> {
validateOptions(options);
return createCache({ ...options }, persistentStorage(options.namespace, options.schemaVersion), false);
}
/** Create a login-scoped sessionStorage cache. Data must survive JSON serialization and decoding. */
export function createSessionCache<T, Q>(options: SessionCacheOptions<T, Q>): ResourceCache<T, Q> {
validateOptions(options);
if (typeof options.sessionId !== "string" || !options.sessionId.trim())
throw new TypeError("sessionId must be nonempty");
return createCache(
{ ...options },
sessionStorageBackend(options.namespace, options.schemaVersion, options.sessionId),
true,
);
}
|