Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

@cacheable/memory

Package Overview
Dependencies
Maintainers
1
Versions
11
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.4
to
2.0.5
+1
-1
dist/index.cjs

@@ -642,3 +642,3 @@ "use strict";

const storeHashSize = this._storeHashSize - 1;
const hash2 = (0, import_utils.hashToNumber)(key, {
const hash2 = (0, import_utils.hashToNumberSync)(key, {
min: 0,

@@ -645,0 +645,0 @@ max: storeHashSize,

// src/index.ts
import {
HashAlgorithm,
hashToNumber,
hashToNumberSync,
shorthandToTime,

@@ -86,3 +86,3 @@ wrapSync

hash,
hashToNumber as hashToNumber2
hashToNumber
} from "@cacheable/utils";

@@ -621,3 +621,3 @@

const storeHashSize = this._storeHashSize - 1;
const hash2 = hashToNumber(key, {
const hash2 = hashToNumberSync(key, {
min: 0,

@@ -764,5 +764,5 @@ max: storeHashSize,

hash,
hashToNumber2 as hashToNumber,
hashToNumber,
maximumMapSize
};
/* v8 ignore next -- @preserve */
{
"name": "@cacheable/memory",
"version": "2.0.4",
"version": "2.0.5",
"description": "High Performance In-Memory Cache for Node.js",

@@ -36,4 +36,4 @@ "type": "module",

"hookified": "^1.12.2",
"keyv": "^5.5.3",
"@cacheable/utils": "^2.2.0"
"keyv": "^5.5.4",
"@cacheable/utils": "^2.3.0"
},

@@ -40,0 +40,0 @@ "keywords": [

+14
-13

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

`CacheableMemory` uses `Map` objects to store the keys and values. To make this scale past the `16,777,216 (2^24) keys` limit of a single `Map` we use a hash to balance the data across multiple `Map` objects. This is done by hashing the key and using the hash to determine which `Map` object to use. The default hashing algorithm is `djb2Hash` but you can change it by setting the `storeHashAlgorithm` property in the options. By default we set the amount of `Map` objects to `16`.
`CacheableMemory` uses `Map` objects to store the keys and values. To make this scale past the `16,777,216 (2^24) keys` limit of a single `Map` we use a hash to balance the data across multiple `Map` objects. This is done by hashing the key and using the hash to determine which `Map` object to use. The default hashing algorithm is `djb2` but you can change it by setting the `storeHashAlgorithm` property in the options. Supported algorithms include DJB2, FNV1, MURMER, and CRC32. By default we set the amount of `Map` objects to `16`.

@@ -149,16 +149,15 @@ NOTE: if you are using the LRU cache feature the `lruSize` no matter how many `Map` objects you have it will be limited to the `16,777,216 (2^24) keys` limit of a single `Map` object. This is because we use a double linked list to manage the LRU cache and it is not possible to have more than `16,777,216 (2^24) keys` in a single `Map` object.

Here is an example of how to use the `storeHashAlgorithm` property:
Here is an example of how to use the `storeHashAlgorithm` property with supported algorithms:
```javascript
import { CacheableMemory } from '@cacheable/memory';
const cache = new CacheableMemory({ storeHashAlgorithm: 'sha256' });
cache.set('key', 'value');
const value = cache.get('key'); // value
```
import { CacheableMemory, HashAlgorithm } from '@cacheable/memory';
If you want to provide your own hashing function you can set the `storeHashAlgorithm` property to a function that takes an object and returns a `number` that is in the range of the amount of `Map` stores you have.
// Using DJB2 (default)
const cache = new CacheableMemory({ storeHashAlgorithm: HashAlgorithm.DJB2 });
```javascript
import { CacheableMemory } from '@cacheable/memory';
const cache = new CacheableMemory({ storeHashAlgorithm: HashAlgorithm.SHA256 });
// Or other non-cryptographic algorithms for better performance
const cache2 = new CacheableMemory({ storeHashAlgorithm: HashAlgorithm.FNV1 });
const cache3 = new CacheableMemory({ storeHashAlgorithm: HashAlgorithm.MURMER });
const cache4 = new CacheableMemory({ storeHashAlgorithm: HashAlgorithm.CRC32 });
cache.set('key', 'value');

@@ -168,2 +167,4 @@ const value = cache.get('key'); // value

**Available algorithms:** DJB2 (default), FNV1, MURMER, CRC32. Note: Cryptographic algorithms (SHA-256, SHA-384, SHA-512) are not recommended for store hashing due to performance overhead.
If you want to provide your own hashing function you can set the `storeHashAlgorithm` property to a function that takes an object and returns a `number` that is in the range of the amount of `Map` stores you have.

@@ -238,3 +239,3 @@

* `storeHashSize`: The number of `Map` objects to use for the cache. Default is `16`.
* `storeHashAlgorithm`: The hashing algorithm to use for the cache. Default is `djb2Hash`.
* `storeHashAlgorithm`: The hashing algorithm to use for the cache. Default is `djb2`. Supported: DJB2, FNV1, MURMER, CRC32.

@@ -263,3 +264,3 @@ ## CacheableMemory - API

* `storeHashSize`: The number of `Map` objects to use for the cache. Default is `16`.
* `storeHashAlgorithm`: The hashing algorithm to use for the cache. Default is `djb2Hash`.
* `storeHashAlgorithm`: The hashing algorithm to use for the cache. Default is `djb2`. Supported: DJB2, FNV1, MURMER, CRC32.
* `keys`: Get the keys in the cache. Not able to be set.

@@ -266,0 +267,0 @@ * `items`: Get the items in the cache as `CacheableStoreItem` example `{ key, value, expires? }`.