@@ -5,7 +5,6 @@ import { KeyBuilderCS } from '../KeyBuilderCS';
55import { ILogger } from '../../logger/types' ;
66import { LOG_PREFIX } from './constants' ;
77import { ISettings } from '../../types' ;
8- import { getStorageHash } from '../KeyBuilder' ;
98import { setToArray } from '../../utils/lang/sets' ;
109
1110/**
@@ -15,21 +14,14 @@ export class SplitsCacheInLocal extends AbstractSplitsCacheSync {
1514
1615 private readonly keys : KeyBuilderCS ;
1716 private readonly log : ILogger ;
18- private readonly storageHash : string ;
1917 private readonly flagSetsFilter : string [ ] ;
2018 private hasSync ?: boolean ;
21- private updateNewFilter ?: boolean ;
2219
23- constructor ( settings : ISettings , keys : KeyBuilderCS , expirationTimestamp ?: number ) {
20+ constructor ( settings : ISettings , keys : KeyBuilderCS ) {
2421 super ( ) ;
2522 this . keys = keys ;
2623 this . log = settings . log ;
27- this . storageHash = getStorageHash ( settings ) ;
2824 this . flagSetsFilter = settings . sync . __splitFiltersValidation . groupedFilters . bySet ;
29-
30- this . _checkExpiration ( expirationTimestamp ) ;
31-
32- this . _checkFilterQuery ( ) ;
3325 }
3426
3527 private _decrementCount ( key : string ) {
@@ -138,19 +130,6 @@ export class SplitsCacheInLocal extends AbstractSplitsCacheSync {
138130 }
139131
140132 setChangeNumber ( changeNumber : number ) : boolean {
141-
142- // when using a new split query, we must update it at the store
143- if ( this . updateNewFilter ) {
144- this . log . info ( LOG_PREFIX + 'SDK key, flags filter criteria or flags spec version was modified. Updating cache' ) ;
145- const storageHashKey = this . keys . buildHashKey ( ) ;
146- try {
147- localStorage . setItem ( storageHashKey , this . storageHash ) ;
148- } catch ( e ) {
149- this . log . error ( LOG_PREFIX + e ) ;
150- }
151- this . updateNewFilter = false ;
152- }
153-
154133 try {
155134 localStorage . setItem ( this . keys . buildSplitsTillKey ( ) , changeNumber + '' ) ;
156135 // update "last updated" timestamp with current time
@@ -212,39 +191,6 @@ export class SplitsCacheInLocal extends AbstractSplitsCacheSync {
212191 }
213192 }
214193
215- /**
216- * Clean Splits cache if its `lastUpdated` timestamp is older than the given `expirationTimestamp`,
217- *
218- * @param expirationTimestamp - if the value is not a number, data will not be cleaned
219- */
220- private _checkExpiration ( expirationTimestamp ?: number ) {
221- let value : string | number | null = localStorage . getItem ( this . keys . buildLastUpdatedKey ( ) ) ;
222- if ( value !== null ) {
223- value = parseInt ( value , 10 ) ;
224- if ( ! isNaNNumber ( value ) && expirationTimestamp && value < expirationTimestamp ) this . clear ( ) ;
225- }
226- }
227-
228- // @TODO eventually remove `_checkFilterQuery`. Cache should be cleared at the storage level, reusing same logic than PluggableStorage
229- private _checkFilterQuery ( ) {
230- const storageHashKey = this . keys . buildHashKey ( ) ;
231- const storageHash = localStorage . getItem ( storageHashKey ) ;
232-
233- if ( storageHash !== this . storageHash ) {
234- try {
235- // mark cache to update the new query filter on first successful splits fetch
236- this . updateNewFilter = true ;
237-
238- // if there is cache, clear it
239- if ( this . getChangeNumber ( ) > - 1 ) this . clear ( ) ;
240-
241- } catch ( e ) {
242- this . log . error ( LOG_PREFIX + e ) ;
243- }
244- }
245- // if the filter didn't change, nothing is done
246- }
247-
248194 getNamesByFlagSets ( flagSets : string [ ] ) : Set < string > [ ] {
249195 return flagSets . map ( flagSet => {
250196 const flagSetKey = this . keys . buildFlagSetKey ( flagSet ) ;
0 commit comments