Registry / database / cache-tags

cache-tags

JSON →
library2.9.1jsnpmunverified

Cache Tags is an npm library (v2.9.1) that adds cache tagging for bulk invalidation, supporting Redis (single node and cluster) as the backend. It wraps the ioredis client to allow associating cache entries with tags, enabling listing entries by tag and invalidating all entries for a tag atomically. Inspired by Drupal 8 and Laravel cache tags, it has a low release cadence and is tested against Redis clusters. Key differentiators include simple tag-based get/set/invalidation and listing operations.

npm install cache-tags
INSTALL
IMPORT
SIG · CACHE-TAGS
C
cache-tags
databasejavascriptv2.9.1
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.

TaggableCache
✓ import { TaggableCache } from 'cache-tags'
✗ const TaggableCache = require('cache-tags')
Package is ESM-only? Actually README shows require, so CJS is supported. Both patterns work.
default
✓ import CacheTags from 'cache-tags'
✗ const CacheTags = require('cache-tags').default
Default export may not exist; prefer named import TaggableCache.
TaggableCache
✓ const { TaggableCache } = require('cache-tags')
✗ const TaggableCache = require('cache-tags').TaggableCache
CJS destructuring works; direct property access also works but less idiomatic.

Demonstrates set/get with tags, listing entries by tag, and invalidation of all entries for a tag.

const { TaggableCache: Redis } = require('cache-tags'); const redis = new Redis('127.0.0.1:6379'); Promise.resolve() .then(() => Promise.all([ redis.tags(['first-tag']).set('entry1', 'Lorem', 1234), redis.tags(['first-tag', 'boring']).set('entry2', 'Ipsum', 2324), ]) ) .then(() => Promise.all([ redis.tags(['first-tag']).get('entry1'), redis.get('entry2'), ]) ) .then(console.log) .then(() => redis.tags(['first-tag']).list()) .then(console.log) .then(() => redis.tags(['boring']).list()) .then(console.log) .then(() => redis.tags(['first-tag']).invalidate()) .then(() => Promise.all([ redis.tags(['first-tag']).get('entry1'), redis.get('entry2'), ]) ) .then(console.log);
Debug
Known issues
breakingRequires Redis server – no in-memory fallback.
fix
Install and run Redis before using the library.
affects: >=1.0.0
deprecatedThe constructor TaggableCache constructor expects ioredis config – not a direct ioredis instance.
fix
Pass connection options (string or object) as constructor argument.
affects: >=1.0.0 <3.0.0
gotchaTagged mode returns a different object – do not reuse the tagged cache client after calling invalidate().
fix
Re-enter tagged mode via redis.tags() after each invalidate() call.
affects: >=1.0.0
gotchaKeys with same tag but different TTL: invalidation removes them all regardless of expiration.
fix
Be aware that invalidation is tag-based, not TTL-based.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
Redis server is not running or not reachable.
fix
Start Redis: `redis-server` (or verify host/port).
TypeError: redis.tags is not a function
Attempting to call .tags() on a regular ioredis instance, not a TaggableCache instance.
fix
Ensure you used `const { TaggableCache: Redis } = require('cache-tags');` and not `const Redis = require('ioredis');`.
TypeError: redis.tags(...).set is not a function
Calling .set() on the result of .tags() before entering tagged mode correctly.
fix
Use `.tags(['my-tag']).set(key, value, ttl)` – note the array of tags, not a string.
Upgrade
Version history
2.9.1latest on npm
Audit
Dependencies
ioredisrequiredThe library wraps ioredis to provide tagged caching on top of Redis
Agent activity
35 hits · last 30 days
node
32
Resources
cache-tags — npm install cache-tags · libregistry