New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

dw-cache

Package Overview
Dependencies
Maintainers
1
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dw-cache - npm Package Compare versions

Comparing version 0.0.76 to 0.0.77

63

dist/index.js

@@ -1,2 +0,2 @@

/*! dw-cache v0.0.76 https://github.com/falsandtru/dw-cache | (c) 2021, falsandtru | (Apache-2.0 AND MPL-2.0) License */
/*! dw-cache v0.0.77 https://github.com/falsandtru/dw-cache | (c) 2021, falsandtru | (Apache-2.0 AND MPL-2.0) License */
(function webpackUniversalModuleDefinition(root, factory) {

@@ -459,2 +459,6 @@ if(typeof exports === 'object' && typeof module === 'object')

this.sweeper = new Sweeper(this.indexes.LRU, settings.sweep.threshold, capacity, settings.sweep.window, settings.sweep.range, settings.sweep.shift);
this.ager = new Ager(capacity, this.indexes.LFU, node => {
this.indexes.LRU.unshiftNode(node);
++this.overlap;
});
this.life = settings.life;

@@ -474,17 +478,5 @@ this.disposer = settings.disposer;

}
escapeHand(node) {
if (node !== this.hand) return;
this.hand = node.prev === node ? undefined : node.prev;
}
advanceHand() {
const node = this.hand ??= this.indexes.LFU.last;
if (node === undefined) return;
this.escapeHand(node);
if (--node.value.age !== 0) return;
this.indexes.LRU.unshiftNode(node);
++this.overlap;
}
evict(node, callback) {
//assert(this.memory.size <= this.capacity);
this.escapeHand(node);
this.ager.escape(node);
const entry = node.value;

@@ -518,3 +510,3 @@ entry.region === 'LFU' && node.list === this.indexes.LRU && --this.overlap;

if (node !== undefined) {
this.escapeHand(node);
this.ager.escape(node);
LRU.unshiftNode(node);

@@ -546,3 +538,3 @@ ++this.overlap;

}
this.advanceHand();
this.ager.advance();
const {

@@ -579,6 +571,6 @@ LRU,

}
this.escapeHand(node);
this.ager.escape(node);
node.moveToHead();
if (node.list === LFU) {
entry.age = (this.capacity - LFU.length + 1) * this.life.LFU;
entry.age = this.ager.age() * this.life.LFU;
}

@@ -643,2 +635,3 @@ this.disposer?.(value$, key$);

this.sweeper.clear();
this.ager.clear();
if (!this.disposer || !this.settings.capture.clear) return void this.memory.clear();

@@ -668,2 +661,3 @@ const memory = this.memory;

this.sweeper.resize(capacity, this.settings.sweep.window, this.settings.sweep.range);
this.ager.resize(capacity);
this.ensure(0);

@@ -713,7 +707,7 @@ }

this.stats.hitLFU();
this.escapeHand(node);
this.ager.escape(node);
node.moveToHead();
}
entry.age = (this.capacity - LFU.length + 1) * life;
this.advanceHand();
entry.age = this.ager.age() * life;
this.ager.advance();
this.coordinate();

@@ -1018,2 +1012,29 @@ }

}
class Ager {
constructor(capacity, target, disposer) {
this.capacity = capacity;
this.target = target;
this.disposer = disposer;
}
age() {
return (0, alias_1.max)(this.capacity - this.target.length, 0) + 1;
}
escape(node) {
if (node !== this.hand) return;
this.hand = node.prev === node ? undefined : node.prev;
}
advance() {
const node = this.hand ??= this.target.last;
if (node === undefined) return;
this.escape(node);
if (--node.value.age !== 0) return;
this.disposer(node);
}
clear() {
this.hand = undefined;
}
resize(capacity) {
this.capacity = capacity;
}
}

@@ -1020,0 +1041,0 @@ /***/ }),

{
"name": "dw-cache",
"version": "0.0.76",
"version": "0.0.77",
"description": "The highest performance constant complexity cache algorithm.",

@@ -53,3 +53,3 @@ "private": false,

"npm-check-updates": "^16.4.1",
"spica": "0.0.680",
"spica": "0.0.681",
"ts-loader": "^9.4.1",

@@ -56,0 +56,0 @@ "typescript": "4.9.3",

@@ -621,3 +621,3 @@ # Dual Window Cache

70-85% of [lru-cache](https://www.npmjs.com/package/lru-cache).
70-90% of [lru-cache](https://www.npmjs.com/package/lru-cache).

@@ -638,29 +638,29 @@ Note that the number of trials per capacity for simulation 1,000,000 is insufficient.

```
'LRUCache new x 10,919 ops/sec ±1.67% (114 runs sampled)'
'LRUCache new x 11,505 ops/sec ±1.39% (117 runs sampled)'
'DW-Cache new x 5,907,995 ops/sec ±0.69% (123 runs sampled)'
'DW-Cache new x 4,658,419 ops/sec ±1.22% (122 runs sampled)'
'LRUCache simulation 10 x 8,589,630 ops/sec ±1.08% (123 runs sampled)'
'LRUCache simulation 10 x 7,560,319 ops/sec ±2.18% (120 runs sampled)'
'DW-Cache simulation 10 x 7,088,696 ops/sec ±0.31% (122 runs sampled)'
'DW-Cache simulation 10 x 5,461,384 ops/sec ±1.70% (122 runs sampled)'
'LRUCache simulation 100 x 8,974,195 ops/sec ±0.56% (122 runs sampled)'
'LRUCache simulation 100 x 7,815,141 ops/sec ±2.01% (120 runs sampled)'
'DW-Cache simulation 100 x 6,261,227 ops/sec ±1.15% (121 runs sampled)'
'DW-Cache simulation 100 x 5,601,175 ops/sec ±1.84% (122 runs sampled)'
'LRUCache simulation 1,000 x 7,942,931 ops/sec ±0.69% (123 runs sampled)'
'LRUCache simulation 1,000 x 6,942,532 ops/sec ±1.90% (119 runs sampled)'
'DW-Cache simulation 1,000 x 5,982,914 ops/sec ±1.35% (122 runs sampled)'
'DW-Cache simulation 1,000 x 5,499,352 ops/sec ±1.95% (121 runs sampled)'
'LRUCache simulation 10,000 x 7,018,158 ops/sec ±1.29% (121 runs sampled)'
'LRUCache simulation 10,000 x 6,286,656 ops/sec ±1.81% (121 runs sampled)'
'DW-Cache simulation 10,000 x 5,269,636 ops/sec ±1.59% (121 runs sampled)'
'DW-Cache simulation 10,000 x 4,704,568 ops/sec ±1.68% (122 runs sampled)'
'LRUCache simulation 100,000 x 4,001,962 ops/sec ±1.41% (114 runs sampled)'
'LRUCache simulation 100,000 x 3,432,725 ops/sec ±1.47% (115 runs sampled)'
'DW-Cache simulation 100,000 x 3,486,851 ops/sec ±1.71% (114 runs sampled)'
'DW-Cache simulation 100,000 x 3,101,250 ops/sec ±1.46% (116 runs sampled)'
'LRUCache simulation 1,000,000 x 2,036,892 ops/sec ±2.66% (102 runs sampled)'
'LRUCache simulation 1,000,000 x 1,496,012 ops/sec ±3.46% (98 runs sampled)'
'DW-Cache simulation 1,000,000 x 1,442,923 ops/sec ±1.82% (111 runs sampled)'
'DW-Cache simulation 1,000,000 x 1,208,734 ops/sec ±2.25% (106 runs sampled)'
```

@@ -667,0 +667,0 @@

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