@cacheable/memory
Advanced tools
+40
-18
@@ -31,9 +31,8 @@ "use strict"; | ||
| module.exports = __toCommonJS(index_exports); | ||
| var import_hookified = require("hookified"); | ||
| var import_memoize = require("@cacheable/memoize"); | ||
| var import_utils = require("@cacheable/utils"); | ||
| var import_hookified = require("hookified"); | ||
| // src/memory-lru.ts | ||
| var ListNode = class { | ||
| // eslint-disable-next-line @typescript-eslint/parameter-properties | ||
| value; | ||
@@ -118,3 +117,6 @@ prev = void 0; | ||
| // Default is djb2Hash | ||
| _store = Array.from({ length: this._storeHashSize }, () => /* @__PURE__ */ new Map()); | ||
| _store = Array.from( | ||
| { length: this._storeHashSize }, | ||
| () => /* @__PURE__ */ new Map() | ||
| ); | ||
| _ttl; | ||
@@ -147,3 +149,8 @@ // Turned off by default | ||
| if (options.lruSize > maximumMapSize) { | ||
| this.emit("error", new Error(`LRU size cannot be larger than ${maximumMapSize} due to Map limitations.`)); | ||
| this.emit( | ||
| "error", | ||
| new Error( | ||
| `LRU size cannot be larger than ${maximumMapSize} due to Map limitations.` | ||
| ) | ||
| ); | ||
| } else { | ||
@@ -159,3 +166,6 @@ this._lruSize = options.lruSize; | ||
| } | ||
| this._store = Array.from({ length: this._storeHashSize }, () => /* @__PURE__ */ new Map()); | ||
| this._store = Array.from( | ||
| { length: this._storeHashSize }, | ||
| () => /* @__PURE__ */ new Map() | ||
| ); | ||
| this.startIntervalCheck(); | ||
@@ -204,3 +214,8 @@ } | ||
| if (value > maximumMapSize) { | ||
| this.emit("error", new Error(`LRU size cannot be larger than ${maximumMapSize} due to Map limitations.`)); | ||
| this.emit( | ||
| "error", | ||
| new Error( | ||
| `LRU size cannot be larger than ${maximumMapSize} due to Map limitations.` | ||
| ) | ||
| ); | ||
| return; | ||
@@ -256,3 +271,6 @@ } | ||
| this._storeHashSize = value; | ||
| this._store = Array.from({ length: this._storeHashSize }, () => /* @__PURE__ */ new Map()); | ||
| this._store = Array.from( | ||
| { length: this._storeHashSize }, | ||
| () => /* @__PURE__ */ new Map() | ||
| ); | ||
| } | ||
@@ -278,3 +296,3 @@ /** | ||
| get keys() { | ||
| const keys = new Array(); | ||
| const keys = []; | ||
| for (const store of this._store) { | ||
@@ -297,3 +315,3 @@ for (const key of store.keys()) { | ||
| get items() { | ||
| const items = new Array(); | ||
| const items = []; | ||
| for (const store of this._store) { | ||
@@ -344,3 +362,3 @@ for (const item of store.values()) { | ||
| getMany(keys) { | ||
| const result = new Array(); | ||
| const result = []; | ||
| for (const key of keys) { | ||
@@ -375,3 +393,3 @@ result.push(this.get(key)); | ||
| getManyRaw(keys) { | ||
| const result = new Array(); | ||
| const result = []; | ||
| for (const key of keys) { | ||
@@ -427,6 +445,3 @@ result.push(this.getRaw(key)); | ||
| const item = { key, value, expires }; | ||
| store.set( | ||
| key, | ||
| item | ||
| ); | ||
| store.set(key, item); | ||
| } | ||
@@ -458,3 +473,3 @@ /** | ||
| hasMany(keys) { | ||
| const result = new Array(); | ||
| const result = []; | ||
| for (const key of keys) { | ||
@@ -485,3 +500,3 @@ const item = this.get(key); | ||
| takeMany(keys) { | ||
| const result = new Array(); | ||
| const result = []; | ||
| for (const key of keys) { | ||
@@ -516,3 +531,6 @@ result.push(this.take(key)); | ||
| clear() { | ||
| this._store = Array.from({ length: this._storeHashSize }, () => /* @__PURE__ */ new Map()); | ||
| this._store = Array.from( | ||
| { length: this._storeHashSize }, | ||
| () => /* @__PURE__ */ new Map() | ||
| ); | ||
| this._lru = new DoublyLinkedList(); | ||
@@ -552,2 +570,3 @@ } | ||
| */ | ||
| // biome-ignore lint/suspicious/noExplicitAny: type format | ||
| clone(value) { | ||
@@ -638,2 +657,3 @@ if (this.isPrimitive(value)) { | ||
| */ | ||
| // biome-ignore lint/suspicious/noExplicitAny: type format | ||
| wrap(function_, options) { | ||
@@ -643,2 +663,3 @@ const wrapOptions = { | ||
| keyPrefix: options?.keyPrefix, | ||
| createKey: options?.createKey, | ||
| cache: this | ||
@@ -648,2 +669,3 @@ }; | ||
| } | ||
| // biome-ignore lint/suspicious/noExplicitAny: type format | ||
| isPrimitive(value) { | ||
@@ -650,0 +672,0 @@ const result = false; |
+1
-1
@@ -1,5 +0,5 @@ | ||
| import { Hookified } from 'hookified'; | ||
| import { WrapFunctionOptions } from '@cacheable/memoize'; | ||
| import { HashAlgorithm, CacheableStoreItem, CacheableItem } from '@cacheable/utils'; | ||
| export { CacheableItem, CacheableStoreItem, HashAlgorithm, hash, hashToNumber } from '@cacheable/utils'; | ||
| import { Hookified } from 'hookified'; | ||
@@ -6,0 +6,0 @@ type StoreHashAlgorithmFunction = (key: string, storeHashSize: number) => number; |
+1
-1
@@ -1,5 +0,5 @@ | ||
| import { Hookified } from 'hookified'; | ||
| import { WrapFunctionOptions } from '@cacheable/memoize'; | ||
| import { HashAlgorithm, CacheableStoreItem, CacheableItem } from '@cacheable/utils'; | ||
| export { CacheableItem, CacheableStoreItem, HashAlgorithm, hash, hashToNumber } from '@cacheable/utils'; | ||
| import { Hookified } from 'hookified'; | ||
@@ -6,0 +6,0 @@ type StoreHashAlgorithmFunction = (key: string, storeHashSize: number) => number; |
+45
-21
| // src/index.ts | ||
| import { Hookified } from "hookified"; | ||
| import { wrapSync } from "@cacheable/memoize"; | ||
| import { | ||
| shorthandToTime, | ||
| wrapSync | ||
| } from "@cacheable/memoize"; | ||
| import { | ||
| HashAlgorithm, | ||
| hashToNumber, | ||
| HashAlgorithm | ||
| shorthandToTime | ||
| } from "@cacheable/utils"; | ||
| import { Hookified } from "hookified"; | ||
| // src/memory-lru.ts | ||
| var ListNode = class { | ||
| // eslint-disable-next-line @typescript-eslint/parameter-properties | ||
| value; | ||
@@ -96,3 +97,6 @@ prev = void 0; | ||
| // Default is djb2Hash | ||
| _store = Array.from({ length: this._storeHashSize }, () => /* @__PURE__ */ new Map()); | ||
| _store = Array.from( | ||
| { length: this._storeHashSize }, | ||
| () => /* @__PURE__ */ new Map() | ||
| ); | ||
| _ttl; | ||
@@ -125,3 +129,8 @@ // Turned off by default | ||
| if (options.lruSize > maximumMapSize) { | ||
| this.emit("error", new Error(`LRU size cannot be larger than ${maximumMapSize} due to Map limitations.`)); | ||
| this.emit( | ||
| "error", | ||
| new Error( | ||
| `LRU size cannot be larger than ${maximumMapSize} due to Map limitations.` | ||
| ) | ||
| ); | ||
| } else { | ||
@@ -137,3 +146,6 @@ this._lruSize = options.lruSize; | ||
| } | ||
| this._store = Array.from({ length: this._storeHashSize }, () => /* @__PURE__ */ new Map()); | ||
| this._store = Array.from( | ||
| { length: this._storeHashSize }, | ||
| () => /* @__PURE__ */ new Map() | ||
| ); | ||
| this.startIntervalCheck(); | ||
@@ -182,3 +194,8 @@ } | ||
| if (value > maximumMapSize) { | ||
| this.emit("error", new Error(`LRU size cannot be larger than ${maximumMapSize} due to Map limitations.`)); | ||
| this.emit( | ||
| "error", | ||
| new Error( | ||
| `LRU size cannot be larger than ${maximumMapSize} due to Map limitations.` | ||
| ) | ||
| ); | ||
| return; | ||
@@ -234,3 +251,6 @@ } | ||
| this._storeHashSize = value; | ||
| this._store = Array.from({ length: this._storeHashSize }, () => /* @__PURE__ */ new Map()); | ||
| this._store = Array.from( | ||
| { length: this._storeHashSize }, | ||
| () => /* @__PURE__ */ new Map() | ||
| ); | ||
| } | ||
@@ -256,3 +276,3 @@ /** | ||
| get keys() { | ||
| const keys = new Array(); | ||
| const keys = []; | ||
| for (const store of this._store) { | ||
@@ -275,3 +295,3 @@ for (const key of store.keys()) { | ||
| get items() { | ||
| const items = new Array(); | ||
| const items = []; | ||
| for (const store of this._store) { | ||
@@ -322,3 +342,3 @@ for (const item of store.values()) { | ||
| getMany(keys) { | ||
| const result = new Array(); | ||
| const result = []; | ||
| for (const key of keys) { | ||
@@ -353,3 +373,3 @@ result.push(this.get(key)); | ||
| getManyRaw(keys) { | ||
| const result = new Array(); | ||
| const result = []; | ||
| for (const key of keys) { | ||
@@ -405,6 +425,3 @@ result.push(this.getRaw(key)); | ||
| const item = { key, value, expires }; | ||
| store.set( | ||
| key, | ||
| item | ||
| ); | ||
| store.set(key, item); | ||
| } | ||
@@ -436,3 +453,3 @@ /** | ||
| hasMany(keys) { | ||
| const result = new Array(); | ||
| const result = []; | ||
| for (const key of keys) { | ||
@@ -463,3 +480,3 @@ const item = this.get(key); | ||
| takeMany(keys) { | ||
| const result = new Array(); | ||
| const result = []; | ||
| for (const key of keys) { | ||
@@ -494,3 +511,6 @@ result.push(this.take(key)); | ||
| clear() { | ||
| this._store = Array.from({ length: this._storeHashSize }, () => /* @__PURE__ */ new Map()); | ||
| this._store = Array.from( | ||
| { length: this._storeHashSize }, | ||
| () => /* @__PURE__ */ new Map() | ||
| ); | ||
| this._lru = new DoublyLinkedList(); | ||
@@ -530,2 +550,3 @@ } | ||
| */ | ||
| // biome-ignore lint/suspicious/noExplicitAny: type format | ||
| clone(value) { | ||
@@ -616,2 +637,3 @@ if (this.isPrimitive(value)) { | ||
| */ | ||
| // biome-ignore lint/suspicious/noExplicitAny: type format | ||
| wrap(function_, options) { | ||
@@ -621,2 +643,3 @@ const wrapOptions = { | ||
| keyPrefix: options?.keyPrefix, | ||
| createKey: options?.createKey, | ||
| cache: this | ||
@@ -626,2 +649,3 @@ }; | ||
| } | ||
| // biome-ignore lint/suspicious/noExplicitAny: type format | ||
| isPrimitive(value) { | ||
@@ -628,0 +652,0 @@ const result = false; |
+17
-30
| { | ||
| "name": "@cacheable/memory", | ||
| "version": "1.0.0", | ||
| "version": "1.0.1", | ||
| "description": "High Performance In-Memory Cache for Node.js", | ||
@@ -24,7 +24,5 @@ "type": "module", | ||
| "devDependencies": { | ||
| "@faker-js/faker": "^9.9.0", | ||
| "@keyv/redis": "^5.0.0", | ||
| "@keyv/valkey": "^1.0.7", | ||
| "@types/eslint": "^9.6.1", | ||
| "@types/node": "^24.1.0", | ||
| "@biomejs/biome": "^2.2.2", | ||
| "@faker-js/faker": "^10.0.0", | ||
| "@types/node": "^24.3.0", | ||
| "@vitest/coverage-v8": "^3.2.4", | ||
@@ -34,12 +32,11 @@ "lru-cache": "^11.1.0", | ||
| "tsup": "^8.5.0", | ||
| "typescript": "^5.8.3", | ||
| "vitest": "^3.2.4", | ||
| "xo": "^1.2.1" | ||
| "typescript": "^5.9.2", | ||
| "vitest": "^3.2.4" | ||
| }, | ||
| "dependencies": { | ||
| "@keyv/bigmap": "^1.0.0", | ||
| "hookified": "^1.10.0", | ||
| "keyv": "^5.4.0", | ||
| "@cacheable/memoize": "^1.1.0", | ||
| "@cacheable/utils": "^1.1.0" | ||
| "hookified": "^1.12.0", | ||
| "keyv": "^5.5.0", | ||
| "@cacheable/memoize": "^1.1.1", | ||
| "@cacheable/utils": "^1.1.1" | ||
| }, | ||
@@ -49,24 +46,13 @@ "keywords": [ | ||
| "high performance", | ||
| "layer 1 caching", | ||
| "layer 2 caching", | ||
| "distributed caching", | ||
| "Keyv storage engine", | ||
| "keyv", | ||
| "memory caching", | ||
| "LRU cache", | ||
| "expiration", | ||
| "CacheableMemory", | ||
| "offline support", | ||
| "distributed sync", | ||
| "secondary store", | ||
| "primary store", | ||
| "non-blocking operations", | ||
| "cache statistics", | ||
| "layered caching", | ||
| "fault tolerant", | ||
| "memory", | ||
| "in-memory", | ||
| "scalable cache", | ||
| "in-memory cache", | ||
| "distributed cache", | ||
| "lruSize", | ||
| "lru", | ||
| "multi-tier cache" | ||
| "lru" | ||
| ], | ||
@@ -80,6 +66,7 @@ "files": [ | ||
| "prepublish": "pnpm build", | ||
| "test": "xo --fix && vitest run --coverage", | ||
| "test:ci": "xo && vitest run --coverage", | ||
| "lint": "biome check --write --error-on-warnings", | ||
| "test": "pnpm lint && vitest run --coverage", | ||
| "test:ci": "biome check --error-on-warnings && vitest run --coverage", | ||
| "clean": "rimraf ./dist ./coverage ./node_modules" | ||
| } | ||
| } |
+2
-2
@@ -7,4 +7,4 @@ [<img align="center" src="https://cacheable.org/logo.svg" alt="Cacheable" />](https://github.com/jaredwray/cacheable) | ||
| [](https://github.com/jaredwray/cacheable/actions/workflows/tests.yml) | ||
| [](https://www.npmjs.com/package/cacheable) | ||
| [](https://www.npmjs.com/package/cacheable) | ||
| [](https://www.npmjs.com/package/@cacheable/memory) | ||
| [](https://www.npmjs.com/package/@cacheable/memory) | ||
| [](https://github.com/jaredwray/cacheable/blob/main/LICENSE) | ||
@@ -11,0 +11,0 @@ |
79208
0.31%9
-25%1617
2.93%Updated
Updated
Updated
Updated