Skip to content

Commit f6fd66c

Browse files
authored
Merge pull request #4875 from DSpace/backport-4834-to-dspace-9_x
[Port dspace-9_x] Update lru-cache
2 parents 064095b + a5863a4 commit f6fd66c

File tree

3 files changed

+13
-33
lines changed

3 files changed

+13
-33
lines changed

package-lock.json

Lines changed: 6 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
"leaflet-providers": "^2.0.0",
135135
"leaflet.markercluster": "^1.5.3",
136136
"lodash-es": "^4.17.21",
137-
"lru-cache": "^7.14.1",
137+
"lru-cache": "^11.2.2",
138138
"markdown-it": "^13.0.1",
139139
"mirador": "^3.4.3",
140140
"mirador-dl-plugin": "^0.13.0",

server.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ import express from 'express';
2424
import * as ejs from 'ejs';
2525
import * as compression from 'compression';
2626
import expressStaticGzip from 'express-static-gzip';
27-
/* eslint-enable import/no-namespace */
28-
import LRU from 'lru-cache';
27+
import { LRUCache } from 'lru-cache';
2928
import { isbot } from 'isbot';
3029
import { createCertificate } from 'pem';
3130
import { createServer } from 'https';
@@ -73,10 +72,10 @@ const cookieParser = require('cookie-parser');
7372
const appConfig: AppConfig = buildAppConfig(join(DIST_FOLDER, 'assets/config.json'));
7473

7574
// cache of SSR pages for known bots, only enabled in production mode
76-
let botCache: LRU<string, any>;
75+
let botCache: LRUCache<string, any>;
7776

7877
// cache of SSR pages for anonymous users. Disabled by default, and only available in production mode
79-
let anonymousCache: LRU<string, any>;
78+
let anonymousCache: LRUCache<string, any>;
8079

8180
// extend environment with app config for server
8281
extendEnvironmentWithAppConfig(environment, appConfig);
@@ -349,7 +348,7 @@ function initCache() {
349348
// Initialize a new "least-recently-used" item cache (where least recently used pages are removed first)
350349
// See https://www.npmjs.com/package/lru-cache
351350
// When enabled, each page defaults to expiring after 1 day (defined in default-app-config.ts)
352-
botCache = new LRU( {
351+
botCache = new LRUCache( {
353352
max: environment.cache.serverSide.botCache.max,
354353
ttl: environment.cache.serverSide.botCache.timeToLive,
355354
allowStale: environment.cache.serverSide.botCache.allowStale,
@@ -361,7 +360,7 @@ function initCache() {
361360
// may expire pages more frequently.
362361
// When enabled, each page defaults to expiring after 10 seconds (defined in default-app-config.ts)
363362
// to minimize anonymous users seeing out-of-date content
364-
anonymousCache = new LRU( {
363+
anonymousCache = new LRUCache( {
365364
max: environment.cache.serverSide.anonymousCache.max,
366365
ttl: environment.cache.serverSide.anonymousCache.timeToLive,
367366
allowStale: environment.cache.serverSide.anonymousCache.allowStale,
@@ -438,7 +437,7 @@ function cacheCheck(req, res, next) {
438437
* @param next the next function
439438
* @returns cached copy (if found) or undefined (if not found)
440439
*/
441-
function checkCacheForRequest(cacheName: string, cache: LRU<string, any>, req, res, next): any {
440+
function checkCacheForRequest(cacheName: string, cache: LRUCache<string, any>, req, res, next): any {
442441
// Get the cache key for this request
443442
const key = getCacheKey(req);
444443

0 commit comments

Comments
 (0)