Registry / storage / cache-flow

cache-flow

JSON →
library1.10.0jsnpmunverified

Cache Flow (v1.10.0) is a Node.js caching library with in-memory and Redis support, featuring automatic cache loading, fallback on Redis disconnection, and a TypeScript @Cacheable decorator. It simplifies caching by eliminating manual get-then-set patterns: you define a CacheLoader with a load method, and calling get() auto-populates and returns cached values. Compared to node-cache or ioredis manually, it offers integrated decorator support, dependency injection compatibility, and configurable serialization. Released under ISC license, last updated in 2022, with moderate release cadence.

npm install cache-flow
INSTALL
IMPORT
SIG · CACHE-FLOW
C
cache-flow
storagejavascriptv1.10.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.

CacheLoader
✓ import { CacheLoader } from 'cache-flow'
✗ const CacheLoader = require('cache-flow').CacheLoader
In TypeScript/ESM, use named import. In CommonJS, require works but types are limited.
@Cacheable
✓ import { Cacheable } from 'cache-flow'
✗ import { @Cacheable } from 'cache-flow'
Decorator name is 'Cacheable', not '@Cacheable'. The '@' is part of TypeScript decorator syntax, not the import.
CacheFlow
✓ import { CacheFlow } from 'cache-flow'
✗ import CacheFlow from 'cache-flow'
CacheFlow is a named export, not a default export.

Shows defining a CacheLoader subclass with automatic loading and caching of values.

// File: MyCache.ts import { CacheLoader } from 'cache-flow'; import 'reflect-metadata'; export class MyCache extends CacheLoader<string, string> { constructor() { super('my-cache', { expirationTime: 60 }); // 60 seconds } protected async load(key: string): Promise<string> { // Simulate fetching data (e.g., from DB) return `value-for-${key}`; } } // File: app.ts import { MyCache } from './MyCache'; const cache = new MyCache(); async function main() { const val1 = await cache.get('foo'); console.log(val1); // 'value-for-foo' const val2 = await cache.get('foo'); console.log(val1 === val2); // true, cached } main();
Debug
Known issues
gotchaCacheLoader's load method must return a Promise (or be async) even if synchronous; otherwise get() may not wait for resolution.
fix
Always declare load as async or return a Promise.
affects: >=1.0.0
gotchaIn TypeScript, reflection metadata must be imported at the top of the entry file before any CacheLoader subclass is defined.
fix
Add 'import "reflect-metadata";' at the very top of your main file.
affects: >=1.0.0
deprecatedThe @Cacheable decorator is only supported with TypeScript and the experimentalDecorators compiler option.
fix
Enable 'experimentalDecorators' in tsconfig.json.
affects: >=1.0.0
gotchaWhen using Redis, if Redis disconnects, the cache falls back to in-memory, but configuration may still refer to Redis settings.
fix
Ensure in-memory fallback behavior is desired; no explicit fix needed, but be aware that data may be stale if Redis reconnects.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot use a namespace name as a generic type parameter. ... 'CacheLoader' refers to a type but is being used as a value here.
Using CacheLoader as a generic type parameter instead of instantiating it.
fix
Ensure CacheLoader<K, V> is used as a base class in 'class MyCache extends CacheLoader<K, V>'.
Reflect.defineMetadata is not a function
reflect-metadata is not imported or not loaded before cache-flow.
fix
Add 'import "reflect-metadata";' at the top of your entry file.
Cannot find module 'ioredis' or its corresponding type declarations.
ioredis not installed even though it's optional.
fix
If not using Redis, ensure your configuration doesn't reference Redis; otherwise install ioredis.
Upgrade
Version history
1.10.0latest on npm
Audit
Dependencies
reflect-metadataoptionalRequired for @Cacheable decorator to work in TypeScript
ioredisoptionalRequired for Redis cache backend
Agent activity
44 hits · last 30 days
node
40
Resources
cache-flow — npm install cache-flow · libregistry