Skip to content

Tag-Based Cache

@farbenmeer/tag-based-cache is a cache library built around tag-based invalidation. Instead of expiring individual keys, you invalidate entire groups of cache entries by their tags — a pattern that maps naturally to how data actually changes in real applications.

Terminal window
npm install @farbenmeer/tag-based-cache

InMemoryCache

SQLite in-memory database. Fast, zero I/O — ideal for development, testing, and single-process deployments.

FilesystemCache

SQLite file-based database. Survives process restarts, suitable for single-host production setups.

RedisCache

Redis-backed distributed cache with pub/sub support. The right choice for multi-host deployments.

All three implement the same Cache interface — swap backends without touching application code.

import { InMemoryCache } from "@farbenmeer/tag-based-cache/in-memory-cache";
const cache = new InMemoryCache();
// Store with tags
await cache.set({
key: "user:1",
data: { name: "Alice" },
ttl: 3600,
tags: ["users", "user:1"],
});
// Retrieve
const entry = await cache.get("user:1");
// { data: { name: "Alice" }, attachment: null }
// Invalidate all entries tagged "users"
await cache.delete(["users"]);
await cache.get("user:1"); // null

Pass a cache instance to createRequestHandler to enable server-side caching:

import { createRequestHandler } from "@farbenmeer/tapi/server";
import { InMemoryCache } from "@farbenmeer/tag-based-cache/in-memory-cache";
const cache = new InMemoryCache();
const handleRequest = createRequestHandler(api, { cache });

See Caching Strategies for the full picture.