Registry / serialization / node-ts-cache-storage-memory

node-ts-cache-storage-memory

JSON →
library4.4.0jsnpmunverified

node-ts-cache-storage-memory is a dedicated in-memory storage module for the node-ts-cache library, designed to provide fast, local caching capabilities within Node.js applications. It is currently stable, with version 4.4.0 being the latest as of April 2026, and follows an active release cadence addressing bug fixes and performance enhancements. A key differentiator is its seamless integration with the node-ts-cache decorator-based caching system and the introduction of an 'enqueue' feature in v4.3.4 to prevent thundering herd problems by ensuring the original method is called only once even under high concurrency. This package focuses solely on in-memory storage, contrasting with other node-ts-cache storage modules like Redis or file-based options, and is primarily intended for scenarios where persistent or distributed caching is not required.

npm install node-ts-cache-storage-memory
INSTALL
IMPORT
SIG · NODE-TS-CACHE-STOR
N
node-ts-cache-storage-memory
serializationjavascriptv4.4.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MemoryStorage
import { MemoryStorage } from 'node-ts-cache-storage-memory'
const MemoryStorage = require('node-ts-cache-storage-memory').MemoryStorage
Primarily designed for TypeScript/ESM environments. CommonJS users should use `require` and access the named export.
Cache
import { Cache } from 'node-ts-cache'
import { Cache } from 'node-ts-cache-storage-memory'
The `Cache` decorator is part of the core `node-ts-cache` package, not the storage module itself.
CacheContainer
import { CacheContainer } from 'node-ts-cache'
const { CacheContainer } = require('node-ts-cache-storage-memory')
Like `Cache`, `CacheContainer` is a core component from `node-ts-cache` for managing cache instances.

Demonstrates how to set up and use `MemoryStorage` with `node-ts-cache` decorators, including basic caching and TTL expiration.

import { Cache, CacheContainer } from "node-ts-cache"; import { MemoryStorage } from "node-ts-cache-storage-memory"; const userCache = new CacheContainer(new MemoryStorage()); class MyService { // Simulate a network call or database query private async fetchUsersFromAPI(): Promise<string[]> { console.log('Fetching users from API...'); return new Promise(resolve => setTimeout(() => resolve([`Max-${Date.now()}`, 'User']), 100)); } @Cache(userCache, { ttl: 60 }) // Cache for 60 seconds public async getUsers(): Promise<string[]> { return this.fetchUsersFromAPI(); } } async function runExample() { const service = new MyService(); console.log('First call:'); let users1 = await service.getUsers(); console.log(users1); console.log('Second call (should be cached):'); let users2 = await service.getUsers(); console.log(users2); await new Promise(resolve => setTimeout(resolve, 61 * 1000)); // Wait for cache to expire console.log('Third call after TTL (should re-fetch):'); let users3 = await service.getUsers(); console.log(users3); } runExample();
Debug
Known issues
breakingTTL unit change in `v4.3.4` (non-lazy mode). Prior to `v4.3.4`, the `ttl` option in non-lazy caching mode was incorrectly interpreted as milliseconds. It is now correctly treated as *seconds*. Users upgrading should review and adjust existing `ttl` configurations to avoid significantly shorter cache durations.
fix
Adjust `ttl` values in your `@Cache` decorators or `CacheContainer` configurations to represent seconds instead of milliseconds.
affects: >=4.3.4
gotchaConcurrency handling improved with 'enqueue' feature in `v4.3.4`. This feature prevents the 'thundering herd' problem by ensuring that when multiple simultaneous calls request an uncached item, the original method is executed only once, with subsequent callers receiving the same result. While beneficial, be aware of this change in behavior if your application logic previously relied on specific timing or multiple concurrent executions of the cached method.
fix
No fix required, this is a behavioral improvement. Review your application logic if it depends on specific timing or multiple simultaneous executions of a cached method.
affects: >=4.3.4
gotchaThis package is a storage implementation for `node-ts-cache`. It requires `node-ts-cache` to be installed and used for the caching decorators and container management. Using `node-ts-cache-storage-memory` standalone will result in runtime errors.
fix
Ensure both `node-ts-cache` and `node-ts-cache-storage-memory` are installed: `npm i node-ts-cache node-ts-cache-storage-memory`.
affects: *
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'registerStorage')
`node-ts-cache` (the main package) is not installed or not correctly imported/initialized, and `node-ts-cache-storage-memory` is attempting to register itself without the core library present.
fix
Ensure `node-ts-cache` is installed alongside `node-ts-cache-storage-memory` (`npm i node-ts-cache node-ts-cache-storage-memory`) and that `CacheContainer` is correctly instantiated with a `MemoryStorage` instance.
ReferenceError: MemoryStorage is not defined
Attempting to use `MemoryStorage` in a CommonJS context without a proper `require` statement, or when the package itself is not installed.
fix
For CommonJS, use `const { MemoryStorage } = require('node-ts-cache-storage-memory');`. For ESM, ensure `import { MemoryStorage } from 'node-ts-cache-storage-memory';` is present and the package is installed.
Error: The "ttl" argument must be a number (received type undefined)
The `ttl` option in the `@Cache` decorator or `CacheContainer` configuration is missing, not a valid number, or its unit was misunderstood, especially after the `v4.3.4` fix for TTL units.
fix
Ensure the `ttl` option is a valid number representing *seconds*. If upgrading to `v4.3.4` or later, remember `ttl` in non-lazy mode now correctly means seconds, not milliseconds.
Upgrade
Version history
4.4.0latest on npm
Audit
Dependencies
node-ts-cacherequiredThis package is an implementation for node-ts-cache and requires the core library for decorators and container management.
Agent activity
4 hits · last 30 days
node
4
Resources
node-ts-cache-storage-memory — npm install node-ts-cache-storage-memory · libregistry