Registry / database / redis-tag-cache

redis-tag-cache

JSON →
library1.2.1jsnpmunverified

Cache and invalidate records in Redis by tags. Version 1.2.1 is the latest stable release (last updated ~2018). Provides a simple API to store key-value pairs with associated tags, and invalidate all records matching one or more tags. Uses ioredis internally and supports custom timeouts per record. Differentiator: tag-based invalidation pattern for efficient cache busting without key enumeration.

npm install redis-tag-cache
INSTALL
IMPORT
SIG · REDIS-TAG-CACHE
R
redis-tag-cache
databasejavascriptv1.2.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.

default (TagCache)
import TagCache from 'redis-tag-cache'
const { TagCache } = require('redis-tag-cache')
Package exports a class as default export. Named import will result in undefined.
TagCache (type usage)
import TagCache from 'redis-tag-cache'
import TagCache from 'redis-tag-cache'; const cache = new TagCache(); // Wrong: missing new
Must instantiate with 'new'.
TagCache (CommonJS)
const TagCache = require('redis-tag-cache').default
const TagCache = require('redis-tag-cache')
CommonJS require returns an object with default property due to ES module interop in TypeScript/Node.

Demonstrates basic usage: create cache instance, set a key with tags, get it, invalidate by tag, and confirm invalidation.

import TagCache from 'redis-tag-cache'; import Redis from 'ioredis'; const cache = new TagCache({ defaultTimeout: 86400, redis: { host: process.env.REDIS_HOST ?? 'localhost', port: Number(process.env.REDIS_PORT ?? 6379), } }); async function main() { await cache.set('mykey', { foo: 'bar' }, ['tag1', 'tag2']); const val = await cache.get('mykey'); console.log(val); // { foo: 'bar' } await cache.invalidate('tag1'); const after = await cache.get('mykey'); console.log(after); // null } main().catch(console.error);
Debug
Known issues
gotchaCache keys are prefixed with 'data:' and tag keys with 'tags:' automatically; avoid collisions by not using these prefixes manually.
fix
Let the library manage prefixes; do not manually set keys starting with 'data:' or 'tags:'.
affects: >=1.0.0
gotchaSetting null or undefined as value will store the string 'null' or 'undefined' via JSON.stringify, not clear the key.
fix
Always use valid JSON-serializable values. Use delete or set to expire instead of storing null.
affects: >=1.0.0
gotchaget() returns null for missing keys but also returns null for expired entries; cannot distinguish between not set and expired.
fix
Design application logic to treat null as 'not found' or 'expired' directly.
affects: >=1.0.0
deprecatedPackage is no longer actively maintained. Last release was in 2018. No TypeScript type definitions included.
fix
Consider using @types/redis-tag-cache if it exists, or migrate to a more modern alternative like ioredis-based caching with tags.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: TagCache is not a constructor
Using named import instead of default import in ES module environment.
fix
Use `import TagCache from 'redis-tag-cache'` instead of `import { TagCache } from 'redis-tag-cache'`.
Error: Cannot find module 'ioredis'
ioredis is a peer dependency and not installed.
fix
Install ioredis: `npm install ioredis` or `yarn add ioredis`.
Uncaught TypeError: cache.get is not a function
Instantiated the class without `new` keyword or imported the wrong symbol.
fix
Ensure you use `new TagCache()` and import default export.
Upgrade
Version history
1.2.1latest on npm
Audit
Dependencies
ioredisrequiredPeer dependency for Redis connection; must be installed separately
Agent activity
15 hits · last 30 days
node
14
Resources
redis-tag-cache — npm install redis-tag-cache · libregistry