Skip to content

FilesystemCache

FilesystemCache is a Cache implementation backed by a file-based SQLite database (via Node.js built-in node:sqlite). Data persists across process restarts.

import { FilesystemCache } from "@farbenmeer/tag-based-cache/filesystem-cache";
new FilesystemCache(filename: string)
  • Parameters:
    • filename: string — Path to the SQLite database file. Created automatically if it does not exist. If the file already exists, it is reused.
const cache = new FilesystemCache("./cache.db");
await cache.set({
key: "book:1",
data: { title: "Dune" },
ttl: 300,
tags: ["books", "book:1"],
});
const entry = await cache.get("book:1");
// { data: { title: "Dune" }, attachment: null }

Same adaptive garbage collection as InMemoryCache — expired entries are cleaned up periodically with an interval that adjusts between 5 seconds and 5 minutes based on activity.

  • Single-process deployments where you need cache persistence across restarts.
  • Situations where an external service like Redis is not available or justified.