{"id":45261,"library":"lambda-cache","title":"lambda-cache","description":"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.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/owenmorgan/lambda-cache","tags":["javascript"],"install":[{"cmd":"npm install lambda-cache","lang":"bash","label":"npm"},{"cmd":"yarn add lambda-cache","lang":"bash","label":"yarn"},{"cmd":"pnpm add lambda-cache","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only; package does not provide a CommonJS default export.","wrong":"const Cache = require('lambda-cache').Cache","symbol":"Cache","correct":"import { Cache } from 'lambda-cache'"},{"note":"Default export is the Cache class itself.","wrong":"import { default as lambdaCache } from 'lambda-cache'","symbol":"Cache (default)","correct":"import lambdaCache from 'lambda-cache'"},{"note":"TypeScript users should use 'import type' for type-only imports to avoid bundling.","wrong":"import { Cache } from 'lambda-cache' (if only using as type)","symbol":"Cache type (TypeScript)","correct":"import type { Cache } from 'lambda-cache'"}],"quickstart":{"code":"import { Cache } from 'lambda-cache';\n\nconst cache = new Cache();\n\nexport const handler = async (event) => {\n  const key = 'myKey';\n  let value = cache.get(key);\n  if (value) {\n    return { statusCode: 200, body: JSON.stringify(value) };\n  }\n  value = { data: 'fresh' };\n  cache.set(key, value, 30); // cache for 30 seconds\n  return { statusCode: 200, body: JSON.stringify(value) };\n};\n","lang":"typescript","description":"Shows basic usage: initialize cache, check for cached value, set value with TTL."},"warnings":[{"fix":"Design for eventual consistency; do not rely on cache being populated across different invocations.","message":"Cache is not shared across execution contexts; only within a single warm invocation.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Only use positive integers for TTL (e.g., 10 for 10 seconds).","message":"TTL values are in seconds; passing 0 or negative values may cause unexpected behavior.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Check for 'if (val === undefined)' or use 'if (!val)' but note falsey values like 0 or empty string are valid cached items.","message":"get() returns undefined for missing keys, not null. Comparing with == or === null may fail.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.0.0':17 'across':27 'api':62 'aw':13 'base':23 'cach':3,9,24,36,50 'call':63 'class':51 'context':33 'depend':75 'environ':44 'execut':32 'expir':57 'extern':61,74 'function':15,71 'generic':35 'get':53 'ideal':58 'improv':65 'in-memori':6 'invoc':28,72 'javascript':76 'lambda':2,14,43 'lambda-cach':1 'librari':10 'lightweight':5 'live':70 'memori':8,46 'node.js':12 'perform':66 'persist':26 'provid':18 'reduc':60 'reus':48 'set':54 'short':69 'short-liv':68 'simpl':20 'solut':37 'stateless':42 'support':52 'tailor':40 'ttl':22,56 'ttl-base':21 'unlik':34 'version':16 'within':29","created_at":"2026-06-07T12:54:08.595557+00:00","updated_at":"2026-06-07T12:54:08.595557+00:00","problems":[{"fix":"Use ES module import: import { Cache } from 'lambda-cache' or import lambdaCache from 'lambda-cache'.","cause":"Using require() with default export incorrectly.","error":"TypeError: cache.get is not a function"},{"fix":"Ensure correct import: import { Cache } from 'lambda-cache'.","cause":"Forgetting to import or wrong import syntax.","error":"ReferenceError: Cache is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/owenmorgan/lambda-cache#readme","github":"https://github.com/owenmorgan/lambda-cache","docs":null,"changelog":null,"pypi":null,"npm":"lambda-cache","openapi_spec":null,"status_page":null,"smithery":null,"categories":["cache"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}