diff --git a/lib/cache/sqlite-cache-store.js b/lib/cache/sqlite-cache-store.js index afbdbc4771d..d782aafbe0b 100644 --- a/lib/cache/sqlite-cache-store.js +++ b/lib/cache/sqlite-cache-store.js @@ -265,8 +265,6 @@ class SqliteCacheStore { callback() }, final (callback) { - store.prune() - const existingValue = store.#findValue(key, true) if (existingValue) { // Updating an existing response, let's overwrite it @@ -283,6 +281,7 @@ class SqliteCacheStore { existingValue.id ) } else { + store.#prune() // New response, let's insert it store.#insertValueQuery.run( url, @@ -316,14 +315,8 @@ class SqliteCacheStore { this.#deleteByUrlQuery.run(this.#makeValueUrl(key)) } - /** - * This method is called to prune the cache when it exceeds the maximum number - * of entries. It removes half the entries in the cache, ordering them the oldest. - * - * @returns {Number} The number of entries removed - */ - prune () { - if (this.size <= this.#maxCount) { + #prune () { + if (this.#size <= this.#maxCount) { return 0 } @@ -348,7 +341,7 @@ class SqliteCacheStore { * Counts the number of rows in the cache * @returns {Number} */ - get size () { + get #size () { const { total } = this.#countEntriesQuery.get() return total }