Skip to content

Commit

Permalink
Clear segments and largeSegments caches
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilianoSanchez committed Dec 18, 2024
1 parent 6605bfc commit 9b8d36a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
9 changes: 3 additions & 6 deletions src/storages/inLocalStorage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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() { },
Expand Down
5 changes: 4 additions & 1 deletion src/storages/inLocalStorage/validateCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9b8d36a

Please sign in to comment.