A middleware-like caching library for async functions (including AsyncFunction and Promise-based) that caches results in Redis using ioredis. Version 4.1.0 is stable, with regular updates. It wraps any async function, caching its return value based on a configurable key (defaults to function name) and TTL. Supports custom get/set logic, conditional caching, manual cache management (get, set, clear, raw), and automatic serialization via JSON. Differentiators: simple API, first-class ioredis support, and fine-grained cache control per function invocation.
npm install co-cacheNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic setup with ioredis, wrapping an async function, cached vs raw execution.
Always provide a custom key option that ensures uniqueness.
Always define a TTL (expire in ms) to avoid unbounded memory usage.
Upgrade to 4.x and provide functions for dynamic keys.
Ensure key function returns a string or if you want to skip, return false explicitly.
const cache = require('co-cache')({ client: redis });Start Redis server or use Redis client with correct host/port.
Use co-cache only in Node.js environment with a proper Redis connection.