Registry / storage / simple-in-memory-cache

simple-in-memory-cache

JSON →
library0.4.0jsnpmunverified

A minimal in-memory cache library for Node.js and the browser, supporting time-based expiration (TTL) policies. Version 0.4.0 provides a simple key-value store with configurable default expiration and per-item overrides, type definitions shipped, and zero dependencies. Designed for lightweight caching needs where full-featured solutions like lru-cache or node-cache are overkill, with a focus on a clean API and ease of use. Last updated in 2020, it is considered stable but in maintenance mode.

npm install simple-in-memory-cache
INSTALL
IMPORT
SIG · SIMPLE-IN-MEMORY-C
S
simple-in-memory-cache
storagejavascriptv0.4.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.

createCache
import { createCache } from 'simple-in-memory-cache'
import createCache from 'simple-in-memory-cache'
This is a named export, not a default export.
Cache
import { type Cache } from 'simple-in-memory-cache'
import { Cache } from 'simple-in-memory-cache'
If you only need the type, use `type` import to avoid runtime issues.
set
const { set } = createCache()
import { set } from 'simple-in-memory-cache'
The `set` function is returned by the `createCache` function, not exported directly.

Demonstrates basic cache operations: set, get, setEx with custom TTL, delete, clear, and size.

import { createCache } from 'simple-in-memory-cache'; const { set, get, setEx, del, clear, size } = createCache({ defaultSecondsUntilExpiration: 60 }); set('key', 'value'); // cached for 60 seconds const value = get('key'); // 'value' setEx('key2', 'value2', 10); // cached for 10 seconds console.log(get('key2')); // 'value2' del('key'); console.log(get('key')); // undefined clear(); console.log(size()); // 0
Debug
Known issues
deprecatedPackage last updated in 2020; no new versions expected.
fix
Consider migrating to actively maintained alternatives like lru-cache or node-cache.
affects: >=0.4.0
gotchaThe `set` function returns a boolean indicating success, but it always returns true; no error handling.
fix
If you need error handling, wrap the call in try/catch or check the return value.
affects: >=0.1.0
gotchaThe `get` function returns `undefined` for expired or missing keys, which can be ambiguous if you stored `undefined` as a value.
fix
Use `has` method or store null instead of undefined to differentiate.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: createCache is not a function
Importing as default instead of named export.
fix
Use import { createCache } from 'simple-in-memory-cache'
Cannot find module 'simple-in-memory-cache'
Module not installed or path incorrect.
fix
Run npm install --save simple-in-memory-cache
Property 'setEx' does not exist on type '{ set: ... }'
Typo in method name; correct is 'setEx' (not 'setex' or 'setEx' with different casing).
fix
Use setEx('key', 'value', secondsUntilExpiration)
Upgrade
Version history
0.4.0latest on npm
Audit
Dependencies
typescriptoptionalRequired during development to compile, but not a runtime dependency.
Agent activity
30 hits · last 30 days
node
26
OpenAI (training)
1
Resources
simple-in-memory-cache — npm install simple-in-memory-cache · libregistry