P0u4a/opfs-cache: Cache large responses on the web with the Origin Private File System


Web Cache API compliant implementation using the Origin Private File System (OPFS) to store responses. Useful for caching large responses such as Hugging Face models or any other large file that exceeds the typical caching quota’s of the browser.

npm install @p0u4a/opfs-cache

Put a response into the cache

const blob = await response.blob();
await cache.put(new Request("https://example.com/path/to/file"), new Response(blob));

Try to match a cached response

const response = await cache.match(new Request("https://example.com/path/to/file"));
const entries = await cache.keys();
await cache.delete(new Request("https://example.com/path/to/file"));

Use as a Custom Cache For Hugging Face Transformers.js

import { OPFSCache } from "@p0u4a/opfs-cache";
import { env } from "@huggingface/transformers";

const opfsModelCache = new OPFSCache("transformers-cache");

env.useBrowserCache = false;
env.useCustomCache = true;
env.customCache = opfsModelCache;



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *