diff --git a/package-lock.json b/package-lock.json index cf7d663..b2b0255 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "lru.min", - "version": "0.2.1", + "version": "0.2.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "lru.min", - "version": "0.2.1", + "version": "0.2.2", "license": "MIT", "devDependencies": { "@biomejs/biome": "^1.8.3", diff --git a/package.json b/package.json index cdbb1d0..08d90aa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lru.min", - "version": "0.2.1", + "version": "0.2.2", "description": "🔥 An extremely fast and efficient LRU cache for JavaScript (Browser compatible) — 4.8KB.", "main": "./lib/index.js", "module": "./lib/index.mjs", diff --git a/src/index.ts b/src/index.ts index 043a608..5949780 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,7 @@ export const createLRU = (options: { /** Maximum number of items the cache can hold. */ max: number; /** Function called when an item is evicted from the cache. */ - onEviction?: (value: Value, key: Key) => unknown; + onEviction?: (key: Key, value: Value) => unknown; }) => { let { max, onEviction } = options; @@ -41,7 +41,7 @@ export const createLRU = (options: { const evictHead = head; const key = keyList[evictHead]!; - onEviction?.(valList[evictHead]!, key); + onEviction?.(key, valList[evictHead]!); keyMap.delete(key); keyList[evictHead] = undefined; @@ -62,7 +62,7 @@ export const createLRU = (options: { keyMap.set(key, index); keyList[index] = key; size++; - } else onEviction?.(valList[index]!, key); + } else onEviction?.(key, valList[index]!); valList[index] = value; @@ -138,7 +138,7 @@ export const createLRU = (options: { const index = keyMap.get(key); if (index !== undefined) { - onEviction?.(valList[index]!, key); + onEviction?.(key, valList[index]!); keyMap.delete(key); free.push(index); @@ -166,7 +166,7 @@ export const createLRU = (options: { /** Clears all key-value pairs from the cache. */ clear(): undefined { for (const index of keyMap.values()) - onEviction?.(valList[index]!, keyList[index]!); + onEviction?.(keyList[index]!, valList[index]!); keyMap.clear(); keyList.fill(undefined);