@tuizi/file-cache
v0.2.0
Published
A simple file cache system for Node.js. The cache is stored in memory and on the filesystem, allowing for fast access and persistence between runs.
Downloads
6
Maintainers
Readme
File Cache
A simple file cache system for Node.js.
Installation
npm install @tuizi/file-cache
Usage
import { FileCache } from "@tuizi/file-cache";
const cache = new FileCache();
// Store a string value in the cache and file system
await cache.set("key", "value");
// Retrieve the value from the cache and file system
const value = await cache.get("key");
// Store a JSON value in the cache and file system
await cache.setJSON("key", { foo: "bar" });
// Retrieve the JSON value from the cache and file system
const jsonValue = await cache.getJSON("key");
Options
ttl
import { FileCache, Ttl } from "@tuizi/file-cache";
// Create a new FileCache instance with a time-to-live (TTL) of 1 day
const cache = new FileCache({
ttl: 1000 * 60 * 60 * 24, // 1 day
});
// Set the value "value" for the key "key" in the cache, with a TTL of the end of the current day
await cache.set("key", "value", Ttl.endOfDay());