[7.17] Update dependency lru-cache to ^11.1.0 (main) (#216517) (#216829)

# Backport

This will backport the following commits from `main` to `7.17`:
- [Update dependency lru-cache to ^11.1.0 (main)
(#216517)](https://github.com/elastic/kibana/pull/216517)

We also need to cherry-pick some changes from
https://github.com/elastic/kibana/pull/206225

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT
[{"author":{"name":"elastic-renovate-prod[bot]","email":"174716857+elastic-renovate-prod[bot]@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-03-31T21:58:09Z","message":"Update
dependency lru-cache to ^11.1.0 (main) (#216517)\n\nThis PR contains the
following updates:\n\n| Package | Type | Update | Change
|\n|---|---|---|---|\n|
[lru-cache](https://redirect.github.com/isaacs/node-lru-cache)
|\ndependencies | minor | [`^11.0.2`
->\n`^11.1.0`](https://renovatebot.com/diffs/npm/lru-cache/11.0.2/11.1.0)
|\n\n---\n\n### Release
Notes\n\n<details>\n<summary>isaacs/node-lru-cache
(lru-cache)</summary>\n\n###\n[`v11.1.0`](https://redirect.github.com/isaacs/node-lru-cache/compare/v11.0.2...v11.1.0)\n\n[Compare\nSource](https://redirect.github.com/isaacs/node-lru-cache/compare/v11.0.2...v11.1.0)\n\n</details>\n\n---\n\n###
Configuration\n\n📅 **Schedule**: Branch creation - At any time (no
schedule defined),\nAutomerge - At any time (no schedule defined).\n\n🚦
**Automerge**: Disabled by config. Please merge this manually once
you\nare satisfied.\n\n♻ **Rebasing**: Whenever PR becomes conflicted,
or you tick the\nrebase/retry checkbox.\n\n🔕 **Ignore**: Close this PR
and you won't be reminded about this update\nagain.\n\n---\n\n- [ ] If
you want to rebase/retry this PR, check\nthis box\n\n---\n\nThis PR has
been generated by
[Renovate\nBot](https://redirect.github.com/renovatebot/renovate).\n\n\n\nCo-authored-by:
elastic-renovate-prod[bot]
<174716857+elastic-renovate-prod[bot]@users.noreply.github.com>","sha":"1846807c25e4e5030b04cca42eef85e40602c0a6","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Core","release_note:skip","v9.0.0","backport:all-open","v8.18.0","v9.1.0","v8.19.0","v8.17.5","v8.16.7"],"title":"Update
dependency lru-cache to ^11.1.0
(main)","number":216517,"url":"https://github.com/elastic/kibana/pull/216517","mergeCommit":{"message":"Update
dependency lru-cache to ^11.1.0 (main) (#216517)\n\nThis PR contains the
following updates:\n\n| Package | Type | Update | Change
|\n|---|---|---|---|\n|
[lru-cache](https://redirect.github.com/isaacs/node-lru-cache)
|\ndependencies | minor | [`^11.0.2`
->\n`^11.1.0`](https://renovatebot.com/diffs/npm/lru-cache/11.0.2/11.1.0)
|\n\n---\n\n### Release
Notes\n\n<details>\n<summary>isaacs/node-lru-cache
(lru-cache)</summary>\n\n###\n[`v11.1.0`](https://redirect.github.com/isaacs/node-lru-cache/compare/v11.0.2...v11.1.0)\n\n[Compare\nSource](https://redirect.github.com/isaacs/node-lru-cache/compare/v11.0.2...v11.1.0)\n\n</details>\n\n---\n\n###
Configuration\n\n📅 **Schedule**: Branch creation - At any time (no
schedule defined),\nAutomerge - At any time (no schedule defined).\n\n🚦
**Automerge**: Disabled by config. Please merge this manually once
you\nare satisfied.\n\n♻ **Rebasing**: Whenever PR becomes conflicted,
or you tick the\nrebase/retry checkbox.\n\n🔕 **Ignore**: Close this PR
and you won't be reminded about this update\nagain.\n\n---\n\n- [ ] If
you want to rebase/retry this PR, check\nthis box\n\n---\n\nThis PR has
been generated by
[Renovate\nBot](https://redirect.github.com/renovatebot/renovate).\n\n\n\nCo-authored-by:
elastic-renovate-prod[bot]
<174716857+elastic-renovate-prod[bot]@users.noreply.github.com>","sha":"1846807c25e4e5030b04cca42eef85e40602c0a6"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/216557","number":216557,"state":"MERGED","mergeCommit":{"sha":"688168bdb6fee380ceea27e256580b3d0de0053c","message":"[9.0]
Update dependency lru-cache to ^11.1.0 (main) (#216517) (#216557)\n\n#
Backport\n\nThis will backport the following commits from `main` to
`9.0`:\n- [Update dependency lru-cache to ^11.1.0
(main)\n(#216517)](https://github.com/elastic/kibana/pull/216517)\n\n\n\n###
Questions ?\nPlease refer to the [Backport
tool\ndocumentation](https://github.com/sorenlouv/backport)\n\n\n\nCo-authored-by:
elastic-renovate-prod[bot]
<174716857+elastic-renovate-prod[bot]@users.noreply.github.com>"}},{"branch":"8.18","label":"v8.18.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/216554","number":216554,"state":"MERGED","mergeCommit":{"sha":"f62aed6dafc7894d315c6c718432fb9c02fb14e8","message":"[8.18]
Update dependency lru-cache to ^11.1.0 (main) (#216517) (#216554)\n\n#
Backport\n\nThis will backport the following commits from `main` to
`8.18`:\n- [Update dependency lru-cache to ^11.1.0
(main)\n(#216517)](https://github.com/elastic/kibana/pull/216517)\n\n\n\n###
Questions ?\nPlease refer to the [Backport
tool\ndocumentation](https://github.com/sorenlouv/backport)\n\n\n\nCo-authored-by:
elastic-renovate-prod[bot]
<174716857+elastic-renovate-prod[bot]@users.noreply.github.com>"}},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/216517","number":216517,"mergeCommit":{"message":"Update
dependency lru-cache to ^11.1.0 (main) (#216517)\n\nThis PR contains the
following updates:\n\n| Package | Type | Update | Change
|\n|---|---|---|---|\n|
[lru-cache](https://redirect.github.com/isaacs/node-lru-cache)
|\ndependencies | minor | [`^11.0.2`
->\n`^11.1.0`](https://renovatebot.com/diffs/npm/lru-cache/11.0.2/11.1.0)
|\n\n---\n\n### Release
Notes\n\n<details>\n<summary>isaacs/node-lru-cache
(lru-cache)</summary>\n\n###\n[`v11.1.0`](https://redirect.github.com/isaacs/node-lru-cache/compare/v11.0.2...v11.1.0)\n\n[Compare\nSource](https://redirect.github.com/isaacs/node-lru-cache/compare/v11.0.2...v11.1.0)\n\n</details>\n\n---\n\n###
Configuration\n\n📅 **Schedule**: Branch creation - At any time (no
schedule defined),\nAutomerge - At any time (no schedule defined).\n\n🚦
**Automerge**: Disabled by config. Please merge this manually once
you\nare satisfied.\n\n♻ **Rebasing**: Whenever PR becomes conflicted,
or you tick the\nrebase/retry checkbox.\n\n🔕 **Ignore**: Close this PR
and you won't be reminded about this update\nagain.\n\n---\n\n- [ ] If
you want to rebase/retry this PR, check\nthis box\n\n---\n\nThis PR has
been generated by
[Renovate\nBot](https://redirect.github.com/renovatebot/renovate).\n\n\n\nCo-authored-by:
elastic-renovate-prod[bot]
<174716857+elastic-renovate-prod[bot]@users.noreply.github.com>","sha":"1846807c25e4e5030b04cca42eef85e40602c0a6"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/216556","number":216556,"state":"MERGED","mergeCommit":{"sha":"5e0a879c735144f97c470e80497353f3136f2dac","message":"[8.x]
Update dependency lru-cache to ^11.1.0 (main) (#216517) (#216556)\n\n#
Backport\n\nThis will backport the following commits from `main` to
`8.x`:\n- [Update dependency lru-cache to ^11.1.0
(main)\n(#216517)](https://github.com/elastic/kibana/pull/216517)\n\n\n\n###
Questions ?\nPlease refer to the [Backport
tool\ndocumentation](https://github.com/sorenlouv/backport)\n\n\n\nCo-authored-by:
elastic-renovate-prod[bot]
<174716857+elastic-renovate-prod[bot]@users.noreply.github.com>"}},{"branch":"8.17","label":"v8.17.5","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/216552","number":216552,"state":"MERGED","mergeCommit":{"sha":"3b2023a544073612a5724fd419c52e7161ded660","message":"[8.17]
Update dependency lru-cache to ^11.1.0 (main) (#216517) (#216552)\n\n#
Backport\n\nThis will backport the following commits from `main` to
`8.17`:\n- [Update dependency lru-cache to ^11.1.0
(main)\n(#216517)](https://github.com/elastic/kibana/pull/216517)\n\n\n\n###
Questions ?\nPlease refer to the [Backport
tool\ndocumentation](https://github.com/sorenlouv/backport)\n\n\n\nCo-authored-by:
elastic-renovate-prod[bot]
<174716857+elastic-renovate-prod[bot]@users.noreply.github.com>"}},{"branch":"8.16","label":"v8.16.7","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/216551","number":216551,"state":"MERGED","mergeCommit":{"sha":"d6666dde0a084aa153a980095c0825bcfccf587d","message":"[8.16]
Update dependency lru-cache to ^11.1.0 (main) (#216517) (#216551)\n\n#
Backport\n\nThis will backport the following commits from `main` to
`8.16`:\n- [Update dependency lru-cache to ^11.1.0
(main)\n(#216517)](https://github.com/elastic/kibana/pull/216517)\n\n\n\n###
Questions ?\nPlease refer to the [Backport
tool\ndocumentation](https://github.com/sorenlouv/backport)\n\n\n\nCo-authored-by:
elastic-renovate-prod[bot]
<174716857+elastic-renovate-prod[bot]@users.noreply.github.com>"}}]}]
BACKPORT-->

---------

Co-authored-by: elastic-renovate-prod[bot] <174716857+elastic-renovate-prod[bot]@users.noreply.github.com>
This commit is contained in:
Alejandro Fernández Haro 2025-04-05 01:35:25 +02:00 committed by GitHub
parent dbd56632c3
commit 33930c1dc1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 37 additions and 35 deletions

View file

@ -282,7 +282,7 @@
"load-json-file": "^6.2.0",
"loader-utils": "^2.0.4",
"lodash": "^4.17.21",
"lru-cache": "^4.1.5",
"lru-cache": "^11.1.0",
"lz-string": "^1.4.4",
"mapbox-gl-draw-rectangle-mode": "1.0.4",
"maplibre-gl": "1.15.2",
@ -563,7 +563,6 @@
"@types/license-checker": "15.0.0",
"@types/loader-utils": "^2.0.3",
"@types/lodash": "^4.14.159",
"@types/lru-cache": "^5.1.0",
"@types/lz-string": "^1.3.34",
"@types/markdown-it": "^12.2.3",
"@types/md5": "^2.2.0",

View file

@ -8,11 +8,11 @@
const { statSync } = require('fs');
const LRU = require('lru-cache');
const LRU = require('lru-cache').LRUCache;
const DIR = Symbol('dir');
const FILE = Symbol('file');
const cache = process.env.KIBANA_RESOLVER_HARD_CACHE ? new Map() : new LRU({ maxAge: 1000 });
const cache = process.env.KIBANA_RESOLVER_HARD_CACHE ? new Map() : new LRU({ ttl: 1000 });
function getPathType(path) {
const cached = cache.get(path);

View file

@ -84,6 +84,7 @@ export function getWebpackConfig(bundle: Bundle, bundleRefs: BundleRefs, worker:
// or which have require() statements that should be ignored because the file is
// already bundled with all its necessary depedencies
noParse: [
/[\/\\]node_modules[\/\\]lru-cache[\/\\]dist[\/\\]commonjs[\/\\]index\.js$/,
/[\/\\]node_modules[\/\\]lodash[\/\\]index\.js$/,
/[\/\\]node_modules[\/\\]vega[\/\\]build-es5[\/\\]vega\.js$/,
],

View file

@ -78,7 +78,10 @@ export default function ({ config: storybookConfig }: { config: Configuration })
// no parse rules for a few known large packages which have no require() statements
// or which have require() statements that should be ignored because the file is
// already bundled with all its necessary dependencies
noParse: [/[\/\\]node_modules[\/\\]vega[\/\\]build-es5[\/\\]vega\.js$/],
noParse: [
/[\/\\]node_modules[\/\\]lru-cache[\/\\]dist[\/\\]commonjs[\/\\]index\.js$/,
/[\/\\]node_modules[\/\\]vega[\/\\]build-es5[\/\\]vega\.js$/,
],
rules: [
{
test: /\.(html|md|txt|tmpl)$/,

View file

@ -6,7 +6,7 @@
* Side Public License, v 1.
*/
import LruCache from 'lru-cache';
import { LRUCache as LruCache } from 'lru-cache';
/** @internal */
export interface IFileHashCache {
@ -21,8 +21,8 @@ export interface IFileHashCache {
export class FileHashCache implements IFileHashCache {
private lru: LruCache<string, Promise<string>>;
constructor(maxSize: number = 250) {
this.lru = new LruCache(maxSize);
constructor(maxItems: number = 250) {
this.lru = new LruCache({ max: maxItems });
}
get(key: string) {
@ -34,6 +34,6 @@ export class FileHashCache implements IFileHashCache {
}
del(key: string) {
this.lru.del(key);
this.lru.delete(key);
}
}

View file

@ -11,22 +11,16 @@ import { CacheManager } from './cache_manager';
describe('CacheManager', () => {
const mockCacheKey = 'mock_key';
const mockCacheItem = 'cache_item';
const cacheDurationMs = 10000;
let mockNow: number;
const cacheDurationMs = 1000;
beforeEach(() => {
jest.useFakeTimers();
mockNow = jest.getRealSystemTime();
jest.setSystemTime(mockNow);
});
afterEach(() => jest.clearAllMocks());
afterAll(() => jest.useRealTimers());
it('caches object for the cache duration only', () => {
it('caches object for the cache duration only', async () => {
const cacheManager = new CacheManager({ cacheDurationMs });
cacheManager.setCache(mockCacheKey, mockCacheItem);
expect(cacheManager.getFromCache(mockCacheKey)).toEqual(mockCacheItem);
jest.advanceTimersByTime(cacheDurationMs + 100);
// Cannot get `jest.FakeTimers` to work with LRUCache
await new Promise((resolve) => setTimeout(resolve, cacheDurationMs + 100));
expect(cacheManager.getFromCache(mockCacheKey)).toEqual(undefined);
});

View file

@ -6,7 +6,7 @@
* Side Public License, v 1.
*/
import LRUCache from 'lru-cache';
import { LRUCache } from 'lru-cache';
export interface CacheManagerConfig {
// cache duration of objects in ms
@ -14,12 +14,12 @@ export interface CacheManagerConfig {
}
export class CacheManager {
private readonly cache: LRUCache<string, unknown>;
private readonly cache: LRUCache<string, {}>;
constructor({ cacheDurationMs }: CacheManagerConfig) {
this.cache = new LRUCache({
max: 1,
maxAge: cacheDurationMs,
ttl: cacheDurationMs,
});
}
@ -27,7 +27,7 @@ export class CacheManager {
* Cache an object by key
*/
public setCache = (cacheKey: string, data: unknown): void => {
this.cache.set(cacheKey, data);
this.cache.set(cacheKey, data as {});
};
/**
@ -41,6 +41,6 @@ export class CacheManager {
* Removes all cached objects
*/
public resetCache(): void {
this.cache.reset();
this.cache.clear();
}
}

View file

@ -7,7 +7,7 @@
import { CoreSetup, CoreStart } from 'kibana/public';
import { isString, startsWith } from 'lodash';
import LRU from 'lru-cache';
import { LRUCache as LRU } from 'lru-cache';
import hash from 'object-hash';
import { enableInspectEsQueries } from '../../../../observability/public';
import { FetchOptions } from '../../../common/fetch_options';
@ -28,10 +28,10 @@ function fetchOptionsWithDebug(fetchOptions: FetchOptions, inspectableEsQueriesE
};
}
const cache = new LRU<string, any>({ max: 100, maxAge: 1000 * 60 * 60 });
const cache = new LRU<string, any>({ max: 100, ttl: 1000 * 60 * 60 });
export function clearCache() {
cache.reset();
cache.clear();
}
export type CallApi = typeof callApi;

View file

@ -6,7 +6,7 @@
*/
import { uniq } from 'lodash';
import LRU from 'lru-cache';
import { LRUCache as LRU } from 'lru-cache';
import { MetricsExplorerRequestBody } from '../../../../common/http_api';
import { getDatasetForField } from './get_dataset_for_field';
import { calculateMetricInterval } from '../../../utils/calculate_metric_interval';
@ -14,7 +14,7 @@ import { ESSearchClient } from '../../../lib/metrics/types';
const cache = new LRU({
max: 100,
maxAge: 15 * 60 * 1000,
ttl: 15 * 60 * 1000,
});
export const findIntervalForMetrics = async (

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import LRU from 'lru-cache';
import { LRUCache as LRU } from 'lru-cache';
import { savedObjectsClientMock, loggingSystemMock } from 'src/core/server/mocks';
import { Logger } from 'src/core/server';
import { PackagePolicyServiceInterface } from '../../../../../../fleet/server';
@ -72,7 +72,7 @@ export const buildManifestManagerMockOptions = (
): ManifestManagerMockOptions => {
const savedObjectMock = savedObjectsClientMock.create();
return {
cache: new LRU<string, Buffer>({ max: 10, maxAge: 1000 * 60 * 60 }),
cache: new LRU<string, Buffer>({ max: 10, ttl: 1000 * 60 * 60 }),
exceptionListClient: listMock.getExceptionListClient(savedObjectMock),
packagePolicyService: createPackagePolicyServiceMock(),
savedObjectsClient: savedObjectMock,

View file

@ -7,7 +7,7 @@
import pMap from 'p-map';
import semver from 'semver';
import LRU from 'lru-cache';
import { LRUCache as LRU } from 'lru-cache';
import { isEqual, isEmpty } from 'lodash';
import { Logger, SavedObjectsClientContract } from 'src/core/server';
import { ListResult } from '../../../../../../fleet/common';

View file

@ -6,7 +6,7 @@
*/
import { Observable } from 'rxjs';
import LRU from 'lru-cache';
import { LRUCache as LRU } from 'lru-cache';
import { estypes } from '@elastic/elasticsearch';
import { Logger, SavedObjectsClient } from '../../../../src/core/server';
@ -119,7 +119,7 @@ export class Plugin implements ISecuritySolutionPlugin {
this.appClientFactory = new AppClientFactory();
// Cache up to three artifacts with a max retention of 5 mins each
this.artifactsCache = new LRU<string, Buffer>({ max: 3, maxAge: 1000 * 60 * 5 });
this.artifactsCache = new LRU<string, Buffer>({ max: 3, ttl: 1000 * 60 * 5 });
this.telemetryEventsSender = new TelemetryEventsSender(this.logger);
this.telemetryReceiver = new TelemetryReceiver(this.logger);

View file

@ -18206,7 +18206,7 @@ lru-cache@10.2.0:
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.2.0.tgz#0bd445ca57363465900f4d1f9bd8db343a4d95c3"
integrity sha512-2bIM8x+VAf6JT4bKAljS1qUWgMsqZRPGJS6FSahIMPVvctcNhyVp7AJu7quxOW9jwkryBReKZY5tY5JYv2n/7Q==
lru-cache@4.1.5, lru-cache@^4.1.5:
lru-cache@4.1.5:
version "4.1.5"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.1.5.tgz#8bbe50ea85bed59bc9e33dcab8235ee9bcf443cd"
integrity sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==
@ -18219,6 +18219,11 @@ lru-cache@^10.2.0:
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.4.3.tgz#410fc8a17b70e598013df257c2446b7f3383f119"
integrity sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==
lru-cache@^11.1.0:
version "11.1.0"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-11.1.0.tgz#afafb060607108132dbc1cf8ae661afb69486117"
integrity sha512-QIXZUBJUx+2zHUdQujWejBkcD9+cs94tLn0+YL8UrCh+D5sCXZ4c7LaEH48pNwRY3MLDgqUFyhlCyjJPf1WP0A==
lru-cache@^5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-5.1.1.tgz#1da27e6710271947695daf6848e847f01d84b920"