Skip to content

Commit

Permalink
refactor: maxEntryCount
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Nov 13, 2024
1 parent 28b10fa commit fff0b2c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
16 changes: 8 additions & 8 deletions lib/cache/memory-cache-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { Writable } = require('node:stream')
* }} MemoryStoreValue
*/
class MemoryCacheStore {
#maxEntries = Infinity
#maxCount = Infinity

#maxEntrySize = Infinity

Expand All @@ -33,15 +33,15 @@ class MemoryCacheStore {
throw new TypeError('MemoryCacheStore options must be an object')
}

if (opts.maxEntries !== undefined) {
if (opts.maxCount !== undefined) {
if (
typeof opts.maxEntries !== 'number' ||
!Number.isInteger(opts.maxEntries) ||
opts.maxEntries < 0
typeof opts.maxCount !== 'number' ||
!Number.isInteger(opts.maxCount) ||
opts.maxCount < 0
) {
throw new TypeError('MemoryCacheStore options.maxEntries must be a non-negative integer')
throw new TypeError('MemoryCacheStore options.maxCount must be a non-negative integer')
}
this.#maxEntries = opts.maxEntries
this.#maxCount = opts.maxCount
}

if (opts.maxEntrySize !== undefined) {
Expand All @@ -58,7 +58,7 @@ class MemoryCacheStore {
}

get isFull () {
return this.#entryCount >= this.#maxEntries
return this.#entryCount >= this.#maxCount
}

/**
Expand Down
4 changes: 3 additions & 1 deletion types/cache-interceptor.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ declare namespace CacheHandler {
/**
* @default Infinity
*/
maxEntries?: number
maxCount?: number

/**
* @default Infinity
*/
maxEntrySize?: number

errorCallback?: (err: Error) => void
}

Expand Down

0 comments on commit fff0b2c

Please sign in to comment.