Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/memory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
"@biomejs/biome": "^2.3.1",
"@faker-js/faker": "^10.1.0",
"@types/node": "^24.9.1",
"@vitest/coverage-v8": "^3.2.4",
"@vitest/coverage-v8": "^4.0.3",
"rimraf": "^6.0.1",
"tsup": "^8.5.0",
"typescript": "^5.9.3",
"vitest": "^3.2.4"
"vitest": "^4.0.3"
},
"dependencies": {
"@cacheable/utils": "workspace:^",
Expand Down
11 changes: 8 additions & 3 deletions packages/memory/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,15 @@ export class CacheableMemory extends Hookified {

if (ttl.ttl) {
const finalTtl = shorthandToTime(ttl.ttl);
/* v8 ignore next -- @preserve */
if (finalTtl !== undefined) {
expires = finalTtl;
}
}
} else {
const finalTtl = shorthandToTime(ttl ?? this._ttl);

/* v8 ignore next -- @preserve */
if (finalTtl !== undefined) {
expires = finalTtl;
}
Expand All @@ -417,6 +419,7 @@ export class CacheableMemory extends Hookified {
this.lruAddToFront(key);
if (this._lru.size > this._lruSize) {
const oldestKey = this._lru.getOldest();
/* v8 ignore next -- @preserve */
if (oldestKey) {
this._lru.removeOldest();
this.delete(oldestKey);
Expand Down Expand Up @@ -613,6 +616,7 @@ export class CacheableMemory extends Hookified {
public lruResize(): void {
while (this._lru.size > this._lruSize) {
const oldestKey = this._lru.getOldest();
/* v8 ignore next -- @preserve */
if (oldestKey) {
this._lru.removeOldest();
this.delete(oldestKey);
Expand Down Expand Up @@ -640,10 +644,10 @@ export class CacheableMemory extends Hookified {
*/
public startIntervalCheck() {
if (this._checkInterval > 0) {
/* c8 ignore next 1 */
/* v8 ignore next -- @preserve */
if (this._interval) {
// Be overly cautious and clear the interval as we've unref'd it and we don't want to leak it
/* c8 ignore next 2 */
/* v8 ignore next -- @preserve */
clearInterval(this._interval);
}

Expand All @@ -658,6 +662,7 @@ export class CacheableMemory extends Hookified {
* @returns {void}
*/
public stopIntervalCheck() {
/* v8 ignore next -- @preserve */
if (this._interval) {
clearInterval(this._interval);
}
Expand Down Expand Up @@ -691,7 +696,7 @@ export class CacheableMemory extends Hookified {
private isPrimitive(value: any): boolean {
const result = false;

/* c8 ignore next 3 */
/* v8 ignore next -- @preserve */
if (value === null || value === undefined) {
return true;
}
Expand Down
1 change: 1 addition & 0 deletions packages/memory/src/keyv-memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export function createKeyv(options?: KeyvCacheableMemoryOptions): Keyv {

// biome-ignore lint/suspicious/noImplicitAnyLet: allowed
let ttl;
/* v8 ignore next -- @preserve */
if (options?.ttl && Number.isInteger(options.ttl)) {
ttl = options?.ttl as number;
}
Expand Down
11 changes: 8 additions & 3 deletions packages/memory/src/memory-lru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,26 @@ export class DoublyLinkedList<T> {
} // Node doesn't exist or is already at the front

// Remove the node from its current position
/* v8 ignore next -- @preserve */
if (node.prev) {
node.prev.next = node.next;
}

/* c8 ignore next 3 */
/* v8 ignore next -- @preserve */
if (node.next) {
node.next.prev = node.prev;
}

// Update tail if necessary
/* v8 ignore next -- @preserve */
if (node === this.tail) {
this.tail = node.prev;
}

// Move node to the front
node.prev = undefined;
node.next = this.head;
/* v8 ignore next -- @preserve */
if (this.head) {
this.head.prev = node;
}
Expand All @@ -66,23 +69,25 @@ export class DoublyLinkedList<T> {

// Get the oldest node (tail)
getOldest(): T | undefined {
/* v8 ignore next -- @preserve */
return this.tail ? this.tail.value : undefined;
}

// Remove the oldest node (tail)
removeOldest(): T | undefined {
/* c8 ignore next 3 */
/* v8 ignore next -- @preserve */
if (!this.tail) {
return undefined;
}

const oldValue = this.tail.value;

/* v8 ignore next -- @preserve */
if (this.tail.prev) {
this.tail = this.tail.prev;
this.tail.next = undefined;
/* c8 ignore next 4 */
} else {
/* v8 ignore next -- @preserve */
this.head = this.tail = undefined;
}

Expand Down