From 6245d226658cc3d7f8fce34691326e5602cfab9c Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Wed, 18 Dec 2024 14:03:08 -0500 Subject: [PATCH] feat(core)!: Remove `makeFifoCache` method (#14786) ref: https://github.com/getsentry/sentry-javascript/issues/14268 Deprecation PR: https://github.com/getsentry/sentry-javascript/pull/14434 Removes `makeFifoCache`. This has no replacement. --- docs/migration/v8-to-v9.md | 1 + packages/core/src/utils-hoist/cache.ts | 70 -------------------------- packages/core/src/utils-hoist/index.ts | 2 - packages/utils/src/index.ts | 5 -- 4 files changed, 1 insertion(+), 77 deletions(-) delete mode 100644 packages/core/src/utils-hoist/cache.ts diff --git a/docs/migration/v8-to-v9.md b/docs/migration/v8-to-v9.md index 6839442e3836..817b388c0dc2 100644 --- a/docs/migration/v8-to-v9.md +++ b/docs/migration/v8-to-v9.md @@ -106,6 +106,7 @@ It will be removed in a future major version. - The `getNumberOfUrlSegments` method has been removed. There is no replacement. - The `validSeverityLevels` export has been removed. There is no replacement. +- The `makeFifoCache` method has been removed. There is no replacement. - The `arrayify` export has been removed. There is no replacement. - The `flatten` export has been removed. There is no replacement. - The `urlEncode` method has been removed. There is no replacement. diff --git a/packages/core/src/utils-hoist/cache.ts b/packages/core/src/utils-hoist/cache.ts deleted file mode 100644 index 376f8ef970cc..000000000000 --- a/packages/core/src/utils-hoist/cache.ts +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Creates a cache that evicts keys in fifo order - * @param size {Number} - * - * @deprecated This function is deprecated and will be removed in the next major version. - */ -export function makeFifoCache( - size: number, -): { - get: (key: Key) => Value | undefined; - add: (key: Key, value: Value) => void; - delete: (key: Key) => boolean; - clear: () => void; - size: () => number; -} { - // Maintain a fifo queue of keys, we cannot rely on Object.keys as the browser may not support it. - let evictionOrder: Key[] = []; - let cache: Record = {}; - - return { - add(key: Key, value: Value) { - while (evictionOrder.length >= size) { - // shift is O(n) but this is small size and only happens if we are - // exceeding the cache size so it should be fine. - const evictCandidate = evictionOrder.shift(); - - if (evictCandidate !== undefined) { - // eslint-disable-next-line @typescript-eslint/no-dynamic-delete - delete cache[evictCandidate]; - } - } - - // in case we have a collision, delete the old key. - if (cache[key]) { - this.delete(key); - } - - evictionOrder.push(key); - cache[key] = value; - }, - clear() { - cache = {}; - evictionOrder = []; - }, - get(key: Key): Value | undefined { - return cache[key]; - }, - size() { - return evictionOrder.length; - }, - // Delete cache key and return true if it existed, false otherwise. - delete(key: Key): boolean { - if (!cache[key]) { - return false; - } - - // eslint-disable-next-line @typescript-eslint/no-dynamic-delete - delete cache[key]; - - for (let i = 0; i < evictionOrder.length; i++) { - if (evictionOrder[i] === key) { - evictionOrder.splice(i, 1); - break; - } - } - - return true; - }, - }; -} diff --git a/packages/core/src/utils-hoist/index.ts b/packages/core/src/utils-hoist/index.ts index 9ba63cb366fc..44ad277225aa 100644 --- a/packages/core/src/utils-hoist/index.ts +++ b/packages/core/src/utils-hoist/index.ts @@ -156,8 +156,6 @@ export { } from './baggage'; export { getSanitizedUrlString, parseUrl, stripUrlQueryAndFragment } from './url'; -// eslint-disable-next-line deprecation/deprecation -export { makeFifoCache } from './cache'; export { eventFromMessage, eventFromUnknownInput, exceptionFromError, parseStackFrames } from './eventbuilder'; export { callFrameToStackFrame, watchdogTimer } from './anr'; export { LRUMap } from './lru'; diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index c7b63720f706..f99d69286bc1 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -106,7 +106,6 @@ import { loadModule as loadModule_imported, logger as logger_imported, makeDsn as makeDsn_imported, - makeFifoCache as makeFifoCache_imported, makePromiseBuffer as makePromiseBuffer_imported, markFunctionWrapped as markFunctionWrapped_imported, maybeInstrument as maybeInstrument_imported, @@ -632,10 +631,6 @@ export const parseUrl = parseUrl_imported; /** @deprecated Import from `@sentry/core` instead. */ export const stripUrlQueryAndFragment = stripUrlQueryAndFragment_imported; -/** @deprecated Import from `@sentry/core` instead. */ -// eslint-disable-next-line deprecation/deprecation -export const makeFifoCache = makeFifoCache_imported; - import type { AddRequestDataToEventOptions as AddRequestDataToEventOptions_imported, InternalGlobal as InternalGlobal_imported,