From 9b8d36af77c55ead5cfafd835d25aae8a3ea4b16 Mon Sep 17 00:00:00 2001 From: Emiliano Sanchez Date: Wed, 18 Dec 2024 15:48:49 -0300 Subject: [PATCH] Clear segments and largeSegments caches --- src/storages/inLocalStorage/index.ts | 9 +++------ src/storages/inLocalStorage/validateCache.ts | 5 ++++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/storages/inLocalStorage/index.ts b/src/storages/inLocalStorage/index.ts index cb14a235..f32cc014 100644 --- a/src/storages/inLocalStorage/index.ts +++ b/src/storages/inLocalStorage/index.ts @@ -14,15 +14,12 @@ import { shouldRecordTelemetry, TelemetryCacheInMemory } from '../inMemory/Telem import { UniqueKeysCacheInMemoryCS } from '../inMemory/UniqueKeysCacheInMemoryCS'; import { getMatching } from '../../utils/key'; import { validateCache } from './validateCache'; - -export interface InLocalStorageOptions { - prefix?: string -} +import SplitIO from '../../../types/splitio'; /** * InLocal storage factory for standalone client-side SplitFactory */ -export function InLocalStorage(options: InLocalStorageOptions = {}): IStorageSyncFactory { +export function InLocalStorage(options: SplitIO.InLocalStorageOptions = {}): IStorageSyncFactory { const prefix = validatePrefix(options.prefix); @@ -53,7 +50,7 @@ export function InLocalStorage(options: InLocalStorageOptions = {}): IStorageSyn uniqueKeys: impressionsMode === NONE ? new UniqueKeysCacheInMemoryCS() : undefined, validateCache() { - return validateCache(settings, keys, splits); + return validateCache(settings, keys, splits, segments, largeSegments); }, destroy() { }, diff --git a/src/storages/inLocalStorage/validateCache.ts b/src/storages/inLocalStorage/validateCache.ts index 331a8df9..f76b77ca 100644 --- a/src/storages/inLocalStorage/validateCache.ts +++ b/src/storages/inLocalStorage/validateCache.ts @@ -4,6 +4,7 @@ import { isNaNNumber } from '../../utils/lang'; import { getStorageHash } from '../KeyBuilder'; import { LOG_PREFIX } from './constants'; import type { SplitsCacheInLocal } from './SplitsCacheInLocal'; +import type { MySegmentsCacheInLocal } from './MySegmentsCacheInLocal'; import { KeyBuilderCS } from '../KeyBuilderCS'; function validateExpiration(settings: ISettings, keys: KeyBuilderCS) { @@ -38,10 +39,12 @@ function validateExpiration(settings: ISettings, keys: KeyBuilderCS) { * - it has expired, i.e., its `lastUpdated` timestamp is older than the given `expirationTimestamp` * - hash has changed, i.e., the SDK key, flags filter criteria or flags spec version was modified */ -export function validateCache(settings: ISettings, keys: KeyBuilderCS, splits: SplitsCacheInLocal): boolean { +export function validateCache(settings: ISettings, keys: KeyBuilderCS, splits: SplitsCacheInLocal, segments: MySegmentsCacheInLocal, largeSegments: MySegmentsCacheInLocal): boolean { if (validateExpiration(settings, keys)) { splits.clear(); + segments.clear(); + largeSegments.clear(); } // Check if the cache is ready