@@ -7,6 +7,7 @@ import { LOG_PREFIX } from './constants';
77import { ISettings } from '../../types' ;
88import { getStorageHash } from '../KeyBuilder' ;
99import { setToArray } from '../../utils/lang/sets' ;
10+ import { DEFAULT_CACHE_EXPIRATION_IN_MILLIS } from '../../utils/constants/browser' ;
1011
1112/**
1213 * ISplitsCacheSync implementation that stores split definitions in browser LocalStorage.
@@ -26,16 +27,17 @@ export class SplitsCacheInLocal extends AbstractSplitsCacheSync {
2627 }
2728
2829 /**
29- * Clean Splits cache if its `lastUpdated` timestamp is older than the given `expirationTimestamp`,
30- *
31- * @param expirationTimestamp - if the value is not a number, data will not be cleaned
30+ * Clean Splits cache if:
31+ * - it has expired, i.e., its `lastUpdated` timestamp is older than the given `expirationTimestamp`
32+ * - hash has changes, i.e., the SDK key, flags filter criteria or flags spec version was modified
3233 */
33- public validateCache ( settings : ISettings , expirationTimestamp ?: number ) {
34+ public validateCache ( settings : ISettings ) {
3435 // _checkExpiration
36+ const expirationTimestamp = Date . now ( ) - DEFAULT_CACHE_EXPIRATION_IN_MILLIS ;
3537 let value : string | number | null = localStorage . getItem ( this . keys . buildLastUpdatedKey ( ) ) ;
3638 if ( value !== null ) {
3739 value = parseInt ( value , 10 ) ;
38- if ( ! isNaNNumber ( value ) && expirationTimestamp && value < expirationTimestamp ) this . clear ( ) ;
40+ if ( ! isNaNNumber ( value ) && value < expirationTimestamp ) this . clear ( ) ;
3941 }
4042
4143 // @TODO eventually remove `_checkFilterQuery`. Cache should be cleared at the storage level, reusing same logic than PluggableStorage
0 commit comments