@peerbit/cache
Advanced tools
Comparing version 1.1.1 to 2.0.0
@@ -37,16 +37,18 @@ // Fifo | ||
trim(time = +new Date()) { | ||
const peek = this.list.head; | ||
let outOfDate = peek && | ||
this.ttl !== undefined && | ||
this._map.get(peek.value).time < time - this.ttl; | ||
while (outOfDate || this.currentSize > this.max) { | ||
const key = this.list.shift(); | ||
if (key !== undefined) { | ||
const cacheValue = this._map.get(key); | ||
outOfDate = this.ttl !== undefined && cacheValue.time < time - this.ttl; | ||
this._map.delete(key); | ||
const wasDeleted = this.deleted.delete(key); | ||
if (!wasDeleted) { | ||
this.currentSize -= cacheValue.size; | ||
for (;;) { | ||
const headKey = this.list.head; | ||
if (headKey?.value !== undefined) { | ||
const cacheValue = this._map.get(headKey.value); | ||
const outOfDate = this.ttl !== undefined && cacheValue.time < time - this.ttl; | ||
if (outOfDate || this.currentSize > this.max) { | ||
this.list.shift(); | ||
this._map.delete(headKey.value); | ||
const wasDeleted = this.deleted.delete(headKey.value); | ||
if (!wasDeleted) { | ||
this.currentSize -= cacheValue.size; | ||
} | ||
} | ||
else { | ||
break; | ||
} | ||
} | ||
@@ -58,25 +60,2 @@ else { | ||
} | ||
/* | ||
trim(time = +new Date()) { | ||
const peek = this.list.head; | ||
let outOfDate = | ||
peek && | ||
this.ttl !== undefined && | ||
this._map.get(peek.value)!.time < time - this.ttl; | ||
while (outOfDate || this.currentSize > this.max) { | ||
const key = this.list.shift(); | ||
if (key !== undefined) { | ||
const cacheValue = this.del(key); | ||
if (cacheValue) { | ||
outOfDate = this.ttl !== undefined && cacheValue.time < time - this.ttl; | ||
this._map.delete(key); | ||
} | ||
} else { | ||
break; | ||
} | ||
} | ||
} | ||
*/ | ||
del(key) { | ||
@@ -83,0 +62,0 @@ const cacheValue = this._map.get(key); |
{ | ||
"name": "@peerbit/cache", | ||
"version": "1.1.1", | ||
"version": "2.0.0", | ||
"description": "Simple cache", | ||
@@ -37,3 +37,3 @@ "type": "module", | ||
"devDependencies": { | ||
"@peerbit/time": "1.0.4", | ||
"@peerbit/time": "2.0.0", | ||
"@types/yallist": "^4.0.1" | ||
@@ -47,3 +47,3 @@ }, | ||
], | ||
"gitHead": "6263a10a6236346d1c45d02dc0bf18eed1dc2995" | ||
"gitHead": "c48cb37d237a25b0bcc849482b43f6941d53e3d5" | ||
} |
@@ -43,16 +43,17 @@ // Fifo | ||
trim(time = +new Date()) { | ||
const peek = this.list.head; | ||
let outOfDate = | ||
peek && | ||
this.ttl !== undefined && | ||
this._map.get(peek.value)!.time < time - this.ttl; | ||
while (outOfDate || this.currentSize > this.max) { | ||
const key = this.list.shift(); | ||
if (key !== undefined) { | ||
const cacheValue = this._map.get(key)!; | ||
outOfDate = this.ttl !== undefined && cacheValue.time < time - this.ttl; | ||
this._map.delete(key); | ||
const wasDeleted = this.deleted.delete(key); | ||
if (!wasDeleted) { | ||
this.currentSize -= cacheValue.size; | ||
for (;;) { | ||
const headKey = this.list.head; | ||
if (headKey?.value !== undefined) { | ||
const cacheValue = this._map.get(headKey.value)!; | ||
const outOfDate = | ||
this.ttl !== undefined && cacheValue.time < time - this.ttl; | ||
if (outOfDate || this.currentSize > this.max) { | ||
this.list.shift(); | ||
this._map.delete(headKey.value); | ||
const wasDeleted = this.deleted.delete(headKey.value); | ||
if (!wasDeleted) { | ||
this.currentSize -= cacheValue.size; | ||
} | ||
} else { | ||
break; | ||
} | ||
@@ -64,26 +65,3 @@ } else { | ||
} | ||
/* | ||
trim(time = +new Date()) { | ||
const peek = this.list.head; | ||
let outOfDate = | ||
peek && | ||
this.ttl !== undefined && | ||
this._map.get(peek.value)!.time < time - this.ttl; | ||
while (outOfDate || this.currentSize > this.max) { | ||
const key = this.list.shift(); | ||
if (key !== undefined) { | ||
const cacheValue = this.del(key); | ||
if (cacheValue) { | ||
outOfDate = this.ttl !== undefined && cacheValue.time < time - this.ttl; | ||
this._map.delete(key); | ||
} | ||
} else { | ||
break; | ||
} | ||
} | ||
} | ||
*/ | ||
del(key: string) { | ||
@@ -90,0 +68,0 @@ const cacheValue = this._map.get(key)!; |
Sorry, the diff of this file is not supported yet
10342
200