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.90 to 0.0.91

62

dist/index.js

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

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

@@ -697,3 +697,3 @@ if(typeof exports === 'object' && typeof module === 'object')

}
resize(capacity, resource = capacity) {
resize(capacity, resource) {
if (capacity >>> 0 !== capacity) throw new Error(`Spica: Cache: Capacity must be integer.`);

@@ -707,3 +707,3 @@ if (capacity >= 1 === false) throw new Error(`Spica: Cache: Capacity must be 1 or more.`);

this.limit = capacity - (capacity * this.settings.scope / 100 >>> 0);
this.resource = resource;
this.resource = resource ?? this.settings.resource ?? capacity;
this.stats.resize(window);

@@ -759,20 +759,20 @@ this.sweeper.resize(capacity, this.settings.sweep.window, this.settings.sweep.range);

if (stats.subtotal() * RESOLUTION % capacity !== 0 || !stats.isReady()) return;
const lenR = LRU.length;
const lenF = LFU.length;
const lenOR = this.overlapLRU;
const lenOF = this.overlapLFU;
const leverage = (0, alias_1.min)((lenF - lenOR + lenOF) * 1000 / (lenR + lenF) | 0, 1000);
const rateR = stats.rateLRU();
const rateF = 10000 - rateR;
const densityR = this.densityR = rateR * leverage;
const densityF = this.densityF = rateF * (1000 - leverage);
const densityFO = stats.offset && stats.rateLFU(true) * (1000 - leverage);
const partR = LRU.length;
const partF = LFU.length;
const overlapR = this.overlapLRU;
const overlapF = this.overlapLFU;
const leverage = (0, alias_1.min)((partF - overlapR + overlapF) * 1000 / (partR + partF) | 0, 1000);
const ratioR = stats.ratioLRU();
const ratioF = 10000 - ratioR;
const densityR = this.densityR = ratioR * leverage;
const densityF = this.densityF = ratioF * (1000 - leverage);
const densityFO = stats.offset && stats.ratioLFU(true) * (1000 - leverage);
// 操作頻度を超えてキャッシュ比率を増減させても余剰比率の消化が追いつかず無駄
// LRUの下限設定ではLRU拡大の要否を迅速に判定できないためLFUのヒット率低下の検出で代替する
if (this.partition > 0 && (densityR > densityF || stats.offset !== 0 && densityF * 100 < densityFO * (100 - stats.offset))) {
if (lenR >= this.capacity - this.partition) {
if (partR >= this.capacity - this.partition) {
this.partition = (0, alias_1.max)(this.partition - this.unit, 0);
}
} else if (this.partition < this.limit && densityF > densityR) {
if (lenF >= this.partition) {
if (partF >= this.partition) {
this.partition = (0, alias_1.min)(this.partition + this.unit, this.limit);

@@ -786,3 +786,3 @@ }

class Stats {
static rate(window, targets, remains, offset) {
static ratio(window, targets, remains, offset) {
const currHits = targets[0];

@@ -816,7 +816,7 @@ const prevHits = targets[1];

}
rateLRU(offset = false) {
return Stats.rate(this.window, [this.currLRUHits, this.prevLRUHits], [this.currLFUHits, this.prevLFUHits], +offset & 0);
ratioLRU(offset = false) {
return Stats.ratio(this.window, [this.currLRUHits, this.prevLRUHits], [this.currLFUHits, this.prevLFUHits], +offset & 0);
}
rateLFU(offset = false) {
return Stats.rate(this.window, [this.currLFUHits, this.prevLFUHits], [this.currLRUHits, this.prevLRUHits], +offset & 0);
ratioLFU(offset = false) {
return Stats.ratio(this.window, [this.currLFUHits, this.prevLFUHits], [this.currLRUHits, this.prevLRUHits], +offset & 0);
}

@@ -844,3 +844,3 @@ subtotal() {

class StatsExperimental extends Stats {
static rate(window, targets, remains, offset) {
static ratio(window, targets, remains, offset) {
let total = 0;

@@ -856,5 +856,5 @@ let hits = 0;

if (subratio <= 0) continue;
const rate = window * subratio / subtotal;
total += subtotal * rate;
hits += targets[i] * rate;
const r = window * subratio / subtotal;
total += subtotal * r;
hits += targets[i] * r;
ratio -= subratio;

@@ -903,7 +903,7 @@ if (ratio <= 0) break;

}
rateLRU(offset = false) {
return StatsExperimental.rate(this.window, this.LRU, this.LFU, +offset && this.offset);
ratioLRU(offset = false) {
return StatsExperimental.ratio(this.window, this.LRU, this.LFU, +offset && this.offset);
}
rateLFU(offset = false) {
return StatsExperimental.rate(this.window, this.LFU, this.LRU, +offset && this.offset);
ratioLFU(offset = false) {
return StatsExperimental.ratio(this.window, this.LFU, this.LRU, +offset && this.offset);
}

@@ -996,4 +996,4 @@ subtotal() {

if (this.prevHits === 0 && this.prevMisses === 0) return false;
const rate = Stats.rate(this.window, [this.currHits, this.prevHits], [this.currMisses, this.prevMisses], 0);
return this.active ??= rate < this.threshold;
const ratio = Stats.ratio(this.window, [this.currHits, this.prevHits], [this.currMisses, this.prevMisses], 0);
return this.active ??= ratio < this.threshold;
}

@@ -1232,4 +1232,4 @@ sweep() {

swap(array, index, this.$length--);
sort(this.cmp, array, index, this.$length, this.stable);
array[this.$length] = undefined;
sort(this.cmp, array, index, this.$length, this.stable);
return node[1];

@@ -1236,0 +1236,0 @@ }

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

@@ -34,5 +34,5 @@ "private": false,

"@types/lru-cache": "7.10.9",
"@types/mocha": "10.0.0",
"@types/mocha": "10.0.1",
"@types/power-assert": "1.5.8",
"@typescript-eslint/parser": "^5.44.0",
"@typescript-eslint/parser": "^5.45.0",
"babel-loader": "^9.1.0",

@@ -54,3 +54,3 @@ "babel-plugin-unassert": "^3.2.0",

"npm-check-updates": "^16.4.3",
"spica": "0.0.695",
"spica": "0.0.696",
"ts-loader": "^9.4.1",

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

@@ -749,2 +749,4 @@ # Dual Window Cache

readonly window?: number;
// Max costs.
// Range: L-
readonly resource?: number;

@@ -765,4 +767,2 @@ readonly age?: number;

readonly sample?: number;
// Max costs.
// Range: L-
readonly resolution?: number;

@@ -769,0 +769,0 @@ readonly offset?: number;

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