{"library":"node-ts-cache-storage-memory","title":"Memory Storage for node-ts-cache","description":"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.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install node-ts-cache-storage-memory"],"cli":null},"imports":["import { MemoryStorage } from 'node-ts-cache-storage-memory'","import { Cache } from 'node-ts-cache'","import { CacheContainer } from 'node-ts-cache'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { Cache, CacheContainer } from \"node-ts-cache\";\nimport { MemoryStorage } from \"node-ts-cache-storage-memory\";\n\nconst userCache = new CacheContainer(new MemoryStorage());\n\nclass MyService {\n    // Simulate a network call or database query\n    private async fetchUsersFromAPI(): Promise<string[]> {\n        console.log('Fetching users from API...');\n        return new Promise(resolve => setTimeout(() => resolve([`Max-${Date.now()}`, 'User']), 100));\n    }\n\n    @Cache(userCache, { ttl: 60 }) // Cache for 60 seconds\n    public async getUsers(): Promise<string[]> {\n        return this.fetchUsersFromAPI();\n    }\n}\n\nasync function runExample() {\n    const service = new MyService();\n\n    console.log('First call:');\n    let users1 = await service.getUsers();\n    console.log(users1);\n\n    console.log('Second call (should be cached):');\n    let users2 = await service.getUsers();\n    console.log(users2);\n\n    await new Promise(resolve => setTimeout(resolve, 61 * 1000)); // Wait for cache to expire\n\n    console.log('Third call after TTL (should re-fetch):');\n    let users3 = await service.getUsers();\n    console.log(users3);\n}\n\nrunExample();","lang":"typescript","description":"Demonstrates how to set up and use `MemoryStorage` with `node-ts-cache` decorators, including basic caching and TTL expiration.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}