Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: maxEntriesCount #3832

Merged
merged 1 commit into from
Nov 14, 2024
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
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
Loading