Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typescript-lru-cache

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typescript-lru-cache - npm Package Compare versions

Comparing version 1.2.3 to 2.0.0

6

dist/index.js
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

@@ -132,2 +132,3 @@ export interface LRUCacheOptions<TKey, TValue> {

* Returns the number of entries in the LRUCache object.
* If the cache has entryExpirationTimeInMS set, expired entries will be removed before the size is returned.
*

@@ -170,2 +171,3 @@ * @returns The number of entries in the cache.

* This will not mark the entry as recently used.
* If the newest node is expired, it will be removed.
*

@@ -193,2 +195,3 @@ * @returns The most recently used (newest) entry in the cache.

* This will not mark the entry as recently used.
* If the oldest node is expired, it will be removed.
*

@@ -331,2 +334,3 @@ * @returns The least recently used (oldest) entry in the cache.

* This does not mark the entry as recently used.
* If the cache has a key but the entry is expired, it will be removed and false will be returned.
*

@@ -512,3 +516,4 @@ * @param key The key of the entry to check if exists

private removeNodeFromListAndLookupTable;
private cleanCache;
}
//# sourceMappingURL=LRUCache.d.ts.map

@@ -51,2 +51,3 @@ "use strict";

* Returns the number of entries in the LRUCache object.
* If the cache has entryExpirationTimeInMS set, expired entries will be removed before the size is returned.
*

@@ -68,2 +69,3 @@ * @returns The number of entries in the cache.

get size() {
this.cleanCache();
return this.lookupTable.size;

@@ -94,2 +96,3 @@ }

* This will not mark the entry as recently used.
* If the newest node is expired, it will be removed.
*

@@ -117,2 +120,6 @@ * @returns The most recently used (newest) entry in the cache.

}
if (this.head.isExpired) {
this.removeNodeFromListAndLookupTable(this.head);
return this.newest;
}
return this.mapNodeToEntry(this.head);

@@ -123,2 +130,3 @@ }

* This will not mark the entry as recently used.
* If the oldest node is expired, it will be removed.
*

@@ -146,2 +154,6 @@ * @returns The least recently used (oldest) entry in the cache.

}
if (this.tail.isExpired) {
this.removeNodeFromListAndLookupTable(this.tail);
return this.oldest;
}
return this.mapNodeToEntry(this.tail);

@@ -319,2 +331,3 @@ }

* This does not mark the entry as recently used.
* If the cache has a key but the entry is expired, it will be removed and false will be returned.
*

@@ -340,3 +353,11 @@ * @param key The key of the entry to check if exists

has(key) {
return this.lookupTable.has(key);
const node = this.lookupTable.get(key);
if (!node) {
return false;
}
if (node.isExpired) {
this.removeNodeFromListAndLookupTable(node);
return false;
}
return true;
}

@@ -629,4 +650,17 @@ /**

}
cleanCache() {
// Don't spend time cleaning if entries don't expire.
if (!this.entryExpirationTimeInMS) {
return;
}
const expiredNodes = [];
for (const node of this.lookupTable.values()) {
if (node.isExpired) {
expiredNodes.push(node);
}
}
expiredNodes.forEach(node => this.removeNodeFromListAndLookupTable(node));
}
}
exports.LRUCache = LRUCache;
//# sourceMappingURL=LRUCache.js.map

46

package.json
{
"name": "typescript-lru-cache",
"version": "1.2.3",
"version": "2.0.0",
"description": "LRU Cache",

@@ -26,7 +26,7 @@ "author": "Robert Herber",

"scripts": {
"benchmark": "ts-node ./src/benchmark/index.ts",
"benchmark": "ts-node ./src/__benchmarks__/index.ts",
"build": "rm -rf ./dist && tsc",
"lint": "eslint .",
"lint-fix": "eslint . --fix",
"prettier": "prettier --write **/*.{ts,js,css,html,json} !**/node_modules/** !**/dist/** !**/coverage/** !**/compiled/**",
"prettier": "prettier --write **/*.{ts,js,css,html,json} !**/node_modules/** !**/dist/** !**/coverage/** !**/compiled/** !**/docs/** !**/reports/**",
"release": "np --no-cleanup --no-2fa",

@@ -44,26 +44,26 @@ "build-circular-dependency-check": "madge --circular ./dist",

"devDependencies": {
"@commitlint/cli": "^15.0.0",
"@commitlint/config-conventional": "^15.0.0",
"@stryker-mutator/core": "^5.5.1",
"@stryker-mutator/jest-runner": "^5.5.1",
"@stryker-mutator/typescript-checker": "^5.5.1",
"@commitlint/cli": "^17.0.3",
"@commitlint/config-conventional": "^17.0.3",
"@stryker-mutator/core": "^6.1.2",
"@stryker-mutator/jest-runner": "^6.1.2",
"@stryker-mutator/typescript-checker": "^6.1.2",
"@types/benchmark": "^2.1.1",
"@types/jest": "^27.0.3",
"@typescript-eslint/eslint-plugin": "^5.5.0",
"@typescript-eslint/parser": "^5.5.0",
"@types/jest": "^28.1.4",
"@typescript-eslint/eslint-plugin": "^5.30.4",
"@typescript-eslint/parser": "^5.30.4",
"benchmark": "^2.1.4",
"eslint": "^8.4.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-jest": "^25.3.0",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^7.0.4",
"jest": "^27.4.3",
"eslint": "^8.19.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-jest": "^26.5.3",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.1",
"jest": "^28.1.2",
"madge": "^5.0.1",
"np": "^7.6.0",
"prettier": "^2.5.0",
"ts-jest": "^27.0.7",
"ts-node": "^10.4.0",
"typedoc": "^0.22.10",
"typescript": "^4.5.2"
"np": "^7.6.2",
"prettier": "^2.7.1",
"ts-jest": "^28.0.5",
"ts-node": "^10.8.2",
"typedoc": "^0.23.5",
"typescript": "^4.7.4"
}
}

@@ -169,2 +169,3 @@ import { LRUCacheNode } from './LRUCacheNode';

* Returns the number of entries in the LRUCache object.
* If the cache has entryExpirationTimeInMS set, expired entries will be removed before the size is returned.
*

@@ -186,2 +187,3 @@ * @returns The number of entries in the cache.

public get size(): number {
this.cleanCache();
return this.lookupTable.size;

@@ -214,2 +216,3 @@ }

* This will not mark the entry as recently used.
* If the newest node is expired, it will be removed.
*

@@ -238,2 +241,7 @@ * @returns The most recently used (newest) entry in the cache.

if (this.head.isExpired) {
this.removeNodeFromListAndLookupTable(this.head);
return this.newest;
}
return this.mapNodeToEntry(this.head);

@@ -245,2 +253,3 @@ }

* This will not mark the entry as recently used.
* If the oldest node is expired, it will be removed.
*

@@ -269,2 +278,7 @@ * @returns The least recently used (oldest) entry in the cache.

if (this.tail.isExpired) {
this.removeNodeFromListAndLookupTable(this.tail);
return this.oldest;
}
return this.mapNodeToEntry(this.tail);

@@ -464,2 +478,3 @@ }

* This does not mark the entry as recently used.
* If the cache has a key but the entry is expired, it will be removed and false will be returned.
*

@@ -485,3 +500,14 @@ * @param key The key of the entry to check if exists

public has(key: TKey): boolean {
return this.lookupTable.has(key);
const node = this.lookupTable.get(key);
if (!node) {
return false;
}
if (node.isExpired) {
this.removeNodeFromListAndLookupTable(node);
return false;
}
return true;
}

@@ -809,2 +835,19 @@

}
private cleanCache(): void {
// Don't spend time cleaning if entries don't expire.
if (!this.entryExpirationTimeInMS) {
return;
}
const expiredNodes: LRUCacheNode<TKey, TValue>[] = [];
for (const node of this.lookupTable.values()) {
if (node.isExpired) {
expiredNodes.push(node);
}
}
expiredNodes.forEach(node => this.removeNodeFromListAndLookupTable(node));
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc