Registry / storage / ioredis-cache

ioredis-cache

JSON →
library2.0.3jsnpmunverified

A promise-based caching library built on top of ioredis for Node.js applications. Version 2.0.3 wraps ioredis to provide a compact, memory-efficient caching interface using Redis hashes. Supports standard cache, hash cache, batch operations, TTL expiration, pattern-based deletion, and atomic acquire operations. Ships TypeScript types. Release cadence is low; maintainer activity has been minimal since late 2023. Differentiators: promise-based API, hash map storage for memory efficiency, and built-in `manyCache` to batch uncached keys.

npm install ioredis-cache
INSTALL
IMPORT
SIG · IOREDIS-CACHE
I
ioredis-cache
storagejavascriptv2.0.3
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
✓ import Cache from 'ioredis-cache'
✗ const Cache = require('ioredis-cache')
Default import is CommonJS compatible; TypeScript also allows `import Cache from 'ioredis-cache'`.
CacheOptions
✓ import type { CacheOptions } from 'ioredis-cache'
✗ import { CacheOptions } from 'ioredis-cache' (if not using type import)
Type only export; use type import for TypeScript.
Parser
✓ import type { Parser } from 'ioredis-cache'
✗ import { Parser } from 'ioredis-cache' (not a runtime export)
Type only export.

Demonstrates basic cache, retrieving, and deleting a cached value with TTL, using TypeScript.

import Redis from 'ioredis'; import Cache from 'ioredis-cache'; const redis = new Redis(); const cache = new Cache(redis); async function main() { const value = await cache.cache('myKey', async () => { const result = await fetch('https://api.example.com/data'); return result.json(); }, 3600); console.log(value); const cached = await cache.getCache('myKey'); console.log(cached); await cache.deleteCache('myKey'); redis.quit(); } main().catch(console.error);
Debug
Known issues
gotchaConstructor argument expects an ioredis instance or CacheOptions object, not a plain Redis options object.
fix
Always pass a configured ioredis instance or an object with `redis` property set to an ioredis instance.
affects: >=2.0.0
breakingIn version 2.0.0, the constructor no longer accepts just a Redis URL string; it must be an ioredis instance or CacheOptions.
fix
Create an ioredis instance first: `new Redis('redis://...')` then pass to constructor.
affects: >=2.0.0
deprecatedUsing `require('ioredis-cache')` with CommonJS is deprecated in favor of ES modules.
fix
Use ES module import syntax: `import Cache from 'ioredis-cache'`.
affects: >=2.0.0
gotchaCalling `cache#cache` with a callback that returns `undefined` will not store the result.
fix
Ensure the callback returns a non-undefined value if caching is desired.
affects: >=1.0.0
gotchaThe `ttl` parameter is in seconds, not milliseconds.
fix
Specify TTL as number of seconds (e.g., 3600 for one hour).
affects: >=1.0.0
deprecatedUsing `cache.redis.quit()` to disconnect is a workaround, not a documented API.
fix
Directly call `redis.quit()` on the ioredis instance you created.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: Class constructor Cache cannot be invoked without 'new'
Trying to call `Cache(...)` without the `new` keyword.
fix
Use `new Cache(redis)` instead of `Cache(redis)`.
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
No Redis server running at the default host/port.
fix
Start Redis server or provide correct connection options to ioredis.
TypeError: Redis is not a constructor
Using `new Redis()` without importing ioredis correctly.
fix
Import ioredis: `import Redis from 'ioredis'` or `const Redis = require('ioredis')`.
Upgrade
Version history
2.0.3latest on npm
Audit
Dependencies
ioredisrequiredPeer dependency for Redis client functionality
Agent activity
22 hits · last 30 days
node
22
Resources
ioredis-cache — npm install ioredis-cache · libregistry