From cc197ccbf13b678196f74cf285d176f736cab945 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Wed, 20 Jul 2022 22:45:06 +0200 Subject: [PATCH] make it possible to control the rendering cache LRU sizes (#29180) * make it possible to control the rendering cache LRU sizes * Update middleware/cache-full-rendering.js Co-authored-by: Robert Sese <734194+rsese@users.noreply.github.com> * Update middleware/cache-full-rendering.js Co-authored-by: Robert Sese <734194+rsese@users.noreply.github.com> Co-authored-by: Robert Sese <734194+rsese@users.noreply.github.com> --- middleware/cache-full-rendering.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/middleware/cache-full-rendering.js b/middleware/cache-full-rendering.js index 1c38903261..fe737de374 100644 --- a/middleware/cache-full-rendering.js +++ b/middleware/cache-full-rendering.js @@ -18,10 +18,14 @@ const HEADER_VALUE_TRANSFERRING = 'transferring' const DISABLE_RENDERING_CACHE = Boolean(JSON.parse(process.env.DISABLE_RENDERING_CACHE || 'false')) +// NOTE: Apr 20, when storing about 200 cheerio instances, the total +// heap size becomes about 2.3GB. +const CHEERIO_CACHE_MAXSIZE = parseInt(process.env.CHEERIO_CACHE_MAXSIZE || 100, 10) + +const GZIP_CACHE_MAXSIZE = parseInt(process.env.GZIP_CACHE_MAXSIZE || 1000, 10) + const cheerioCache = new QuickLRU({ - // NOTE: Apr 20, when storing about 200 cheerio instances, the total - // heap size becomes about 2.3GB. - maxSize: 100, + maxSize: CHEERIO_CACHE_MAXSIZE, // Don't use arrow function so we can access `this`. onEviction: function onEviction() { const { heapUsed } = process.memoryUsage() @@ -30,7 +34,7 @@ const cheerioCache = new QuickLRU({ }) const gzipCache = new QuickLRU({ - maxSize: 1000, + maxSize: GZIP_CACHE_MAXSIZE, // Don't use arrow function so we can access `this`. onEviction: function onEviction() { const { heapUsed } = process.memoryUsage()