Registry / storage / express-tag-cache

express-tag-cache

JSON →
library2.2.0jsnpmunverified

A tag-based Redis caching middleware for Express applications, version 2.2.0. It allows caching of HTTP responses in Redis and invalidating them by tags, supporting static and dynamic tag resolution. Fully typed with TypeScript, it includes context awareness for multi-tenant setups and cross-service cache operations. Released under MIT license with a regular release cadence. Key differentiators: tag-based invalidation over key-based, built-in support for tag index pruning (strict/lazy mode), size guard for cache entries, and options for hard/soft invalidation.

npm install express-tag-cache
INSTALL
IMPORT
SIG · EXPRESS-TAG-CACHE
E
express-tag-cache
storagejavascriptv2.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TagCache
import { TagCache } from 'express-tag-cache'
const TagCache = require('express-tag-cache')
ESM-only; CommonJS require() will not work as the package is ESM-only since v2.
TagcacheMiddleware
import { TagcacheMiddleware } from 'express-tag-cache'
import TagcacheMiddleware from 'express-tag-cache'
Named export, not default. Common mistake: using default import.
TagcacheMiddlewareInvalidateOpts
import type { TagcacheMiddlewareInvalidateOpts } from 'express-tag-cache'
Type import: only needed for TypeScript. No common wrong pattern.

Initialize Redis client, TagCache, and TagcacheMiddleware, then cache a GET route with static tags.

import { createClient } from 'redis'; import express from 'express'; import { TagCache, TagcacheMiddleware } from 'express-tag-cache'; const app = express(); const redisClient = createClient(); await redisClient.connect(); const tagcache = new TagCache({ redis: redisClient, cachePrefix: 'cache:', tagPrefix: 'tag:', cacheTtl: 300, tagTtl: 600, }); const cacheMiddleware = new TagcacheMiddleware({ tagcache, enable: true }); app.get('/api/users', cacheMiddleware.cache(['users', 'list']), async (req, res) => { res.json({ users: [] }); }); app.listen(3000);
Debug
Known issues
breakingThe second argument of cacheMiddleware.invalidate() changed from a string (appContext) to an options object in v2.0.0.
fix
Change invalidate(['tags'], 'my-app') to invalidate(['tags'], { appContext: 'my-app' }).
affects: >=2.0.0
breakingPackage is ESM-only since v2; CommonJS require() throws error.
fix
Use import statements or dynamic import() in Node.js with ESM enabled.
affects: >=2.0.0
deprecatedThe 'strict' tag index maintenance mode may be deprecated in future in favor of 'lazy' for performance.
fix
Consider using tagIndexMaintenanceMode: 'lazy' for better performance.
affects: >=2.0.0
gotchaStatic tags must be strings; functions are only for dynamic tags. Mixing types incorrectly may cause runtime errors.
fix
Ensure cache() array contains only strings or functions, not a mix of both in the same element.
affects: >=1.0.0
Errors
Common errors & fixes
ERR_INVALID_ARG_TYPE: The "options.appContext" property must be of type string, received undefined
Passing appContext as a string instead of an object to invalidate() in v2.
fix
Use invalidate(['tags'], { appContext: 'my-app' }) instead of invalidate(['tags'], 'my-app').
TypeError: tagcache.cache is not a function
Using default import on a named export.
fix
Use import { TagcacheMiddleware } from 'express-tag-cache' instead of import TagcacheMiddleware from 'express-tag-cache'.
ERR_REQUIRE_ESM: require() of ES Module not supported
Using require() on an ESM-only package.
fix
Switch to import statements or use dynamic import().
Upgrade
Version history
2.2.0latest on npm
Audit
Dependencies
expressrequiredPeer dependency: Express framework (v4 or v5) is required to use the middleware.
redisrequiredPeer dependency: Redis client (v4 or v5) is required for caching backend.
Agent activity
27 hits · last 30 days
node
24
Amazon
1
Resources
express-tag-cache — npm install express-tag-cache · libregistry