Registry / cache / lambda-cache

lambda-cache

JSON →
library1.0.0jsnpmunverified

A lightweight in-memory caching library for Node.js AWS Lambda functions. Version 1.0.0 provides a simple TTL-based cache that persists across invocations within the same execution context. Unlike generic caching solutions, it is tailored for stateless Lambda environments where memory is reused. The Cache class supports get, set, and TTL expiration. Ideal for reducing external API calls and improving performance in short-lived function invocations. No external dependencies.

npm install lambda-cache
INSTALL
IMPORT
SIG · LAMBDA-CACHE
L
lambda-cache
cachejavascriptv1.0.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.

Cache
import { Cache } from 'lambda-cache'
const Cache = require('lambda-cache').Cache
ESM-only; package does not provide a CommonJS default export.
Cache (default)
import lambdaCache from 'lambda-cache'
import { default as lambdaCache } from 'lambda-cache'
Default export is the Cache class itself.
Cache type (TypeScript)
import type { Cache } from 'lambda-cache'
import { Cache } from 'lambda-cache' (if only using as type)
TypeScript users should use 'import type' for type-only imports to avoid bundling.

Shows basic usage: initialize cache, check for cached value, set value with TTL.

import { Cache } from 'lambda-cache'; const cache = new Cache(); export const handler = async (event) => { const key = 'myKey'; let value = cache.get(key); if (value) { return { statusCode: 200, body: JSON.stringify(value) }; } value = { data: 'fresh' }; cache.set(key, value, 30); // cache for 30 seconds return { statusCode: 200, body: JSON.stringify(value) }; };
Debug
Known issues
gotchaCache is not shared across execution contexts; only within a single warm invocation.
fix
Design for eventual consistency; do not rely on cache being populated across different invocations.
affects: >=1.0.0
gotchaTTL values are in seconds; passing 0 or negative values may cause unexpected behavior.
fix
Only use positive integers for TTL (e.g., 10 for 10 seconds).
affects: >=1.0.0
gotchaget() returns undefined for missing keys, not null. Comparing with == or === null may fail.
fix
Check for 'if (val === undefined)' or use 'if (!val)' but note falsey values like 0 or empty string are valid cached items.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: cache.get is not a function
Using require() with default export incorrectly.
fix
Use ES module import: import { Cache } from 'lambda-cache' or import lambdaCache from 'lambda-cache'.
ReferenceError: Cache is not defined
Forgetting to import or wrong import syntax.
fix
Ensure correct import: import { Cache } from 'lambda-cache'.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
35 hits · last 30 days
node
32
Resources
lambda-cache — npm install lambda-cache · libregistry