Sign In

@cacheable/memory

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cacheable/memory - npm Package Compare versions

Comparing version
2.0.8
to
2.0.9
+2
-6
package.json
{
"name": "@cacheable/memory",
"version": "2.0.8",
"version": "2.0.9",
"description": "High Performance In-Memory Cache for Node.js",

@@ -30,5 +30,2 @@ "type": "module",

"devDependencies": {
"@faker-js/faker": "^10.3.0",
"@types/node": "^25.3.0",
"rimraf": "^6.1.3",
"tsup": "^8.5.1",

@@ -41,3 +38,3 @@ "typescript": "^5.9.3"

"keyv": "^5.6.0",
"@cacheable/utils": "^2.4.0"
"@cacheable/utils": "^2.4.1"
},

@@ -65,3 +62,2 @@ "keywords": [

"build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --clean",
"prepublish": "pnpm build",
"lint": "biome check --write --error-on-warnings",

@@ -68,0 +64,0 @@ "test": "pnpm lint && vitest run --coverage",

@@ -11,3 +11,3 @@ [<img align="center" src="https://cacheable.org/logo.svg" alt="Cacheable" />](https://github.com/jaredwray/cacheable)

You can use `CacheableMemory` as a standalone cache or as a primary store for `cacheable`. You can also set the `useClones` property to `false` if you want to use the same reference for the values. This is useful if you are using large objects and want to save memory. The `lruSize` property is the size of the LRU cache and is set to `0` by default which is unlimited. When setting the `lruSize` property it will limit the number of keys in the cache.
You can use `CacheableMemory` as a standalone cache or as a primary store for `cacheable`. You can also set the `useClones` property to `false` if you want to use the same reference for the values. This is useful if you are using large objects and want to save memory. The `lruSize` property is the size of the LRU cache and is set to `0` by default, which disables the LRU cache (no LRU eviction is performed and the cache size is bounded only by the underlying `Map` stores). When the `lruSize` property is set to a value greater than `0`, it limits the number of keys in the cache and evicts the least recently used entries when full.

@@ -192,7 +192,7 @@ This simple in-memory cache uses multiple Map objects and a with `expiration` and `lru` policies if set to manage the in memory cache at scale.

When you set the `lruSize` we use a double linked list to manage the LRU cache and also set the `hashStoreSize` to `1` which means we will only use a single `Map` object for the LRU cache. This is because the LRU cache is managed by the double linked list and it is not possible to have more than `16,777,216 (2^24) keys` in a single `Map` object.
When you set the `lruSize`, we use a doubly linked list to track the LRU order across the underlying `Map` stores. The `lruSize` itself is capped at `16,777,216 (2^24) keys` — values above this limit are rejected and an `error` event is emitted. Setting `lruSize` does not change `storeHashSize`; the underlying stores keep whatever `storeHashSize` you configured (default `16`).
```javascript
import { CacheableMemory } from 'cacheable';
const cache = new CacheableMemory({ lruSize: 1 }); // sets the LRU cache size to 1000 keys and hashStoreSize to 1
const cache = new CacheableMemory({ lruSize: 1 }); // sets the LRU cache size to 1 key
cache.set('key1', 'value1');

@@ -235,3 +235,3 @@ cache.set('key2', 'value2');

* `useClones`: If the cache should use clones for the values. Default is `true`.
* `lruSize`: The size of the LRU cache. Default is `0` which is unlimited.
* `lruSize`: The size of the LRU cache. Default is `0`, which disables the LRU cache (no LRU eviction is performed). Maximum is `16,777,216 (2^24)`.
* `checkInterval`: The interval to check for expired keys in milliseconds. Default is `0` which is disabled.

@@ -259,3 +259,3 @@ * `storeHashSize`: The number of `Map` objects to use for the cache. Default is `16`.

* `useClones`: If the cache should use clones for the values. Default is `true`.
* `lruSize`: The size of the LRU cache. Default is `0` which is unlimited.
* `lruSize`: The size of the LRU cache. Default is `0`, which disables the LRU cache (no LRU eviction is performed). Maximum is `16,777,216 (2^24)`.
* `size`: The number of keys in the cache.

@@ -262,0 +262,0 @@ * `checkInterval`: The interval to check for expired keys in milliseconds. Default is `0` which is disabled.