Skip to content

Commit ffd724d

Browse files
Remove SplitsCacheInLocal::storageHash
1 parent 1b061eb commit ffd724d

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

src/storages/inLocalStorage/SplitsCacheInLocal.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@ export class SplitsCacheInLocal extends AbstractSplitsCacheSync {
1515

1616
private readonly keys: KeyBuilderCS;
1717
private readonly log: ILogger;
18-
private readonly storageHash: string;
1918
private readonly flagSetsFilter: string[];
2019
private hasSync?: boolean;
2120

2221
constructor(settings: ISettings, keys: KeyBuilderCS) {
2322
super();
2423
this.keys = keys;
2524
this.log = settings.log;
26-
this.storageHash = getStorageHash(settings);
2725
this.flagSetsFilter = settings.sync.__splitFiltersValidation.groupedFilters.bySet;
2826
}
2927

@@ -32,7 +30,7 @@ export class SplitsCacheInLocal extends AbstractSplitsCacheSync {
3230
*
3331
* @param expirationTimestamp - if the value is not a number, data will not be cleaned
3432
*/
35-
public validateCache(expirationTimestamp?: number) {
33+
public validateCache(settings: ISettings, expirationTimestamp?: number) {
3634
// _checkExpiration
3735
let value: string | number | null = localStorage.getItem(this.keys.buildLastUpdatedKey());
3836
if (value !== null) {
@@ -44,14 +42,15 @@ export class SplitsCacheInLocal extends AbstractSplitsCacheSync {
4442
// _checkFilterQuery
4543
const storageHashKey = this.keys.buildHashKey();
4644
const storageHash = localStorage.getItem(storageHashKey);
45+
const currentStorageHash = getStorageHash(settings);
4746

48-
if (storageHash !== this.storageHash) {
47+
if (storageHash !== currentStorageHash) {
4948
this.log.info(LOG_PREFIX + 'SDK key, flags filter criteria or flags spec version was modified. Updating cache');
5049
try {
5150
// if there is cache, clear it
5251
if (this.getChangeNumber() > -1) this.clear();
5352

54-
localStorage.setItem(storageHashKey, this.storageHash);
53+
localStorage.setItem(storageHashKey, currentStorageHash);
5554
} catch (e) {
5655
this.log.error(LOG_PREFIX + e);
5756
}

src/storages/inLocalStorage/__tests__/SplitsCacheInLocal.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { fullSettings } from '../../../utils/settingsValidation/__tests__/settin
77

88
test('SPLIT CACHE / LocalStorage', () => {
99
const cache = new SplitsCacheInLocal(fullSettings, new KeyBuilderCS('SPLITIO', 'user'));
10-
cache.validateCache();
10+
cache.validateCache(fullSettings);
1111

1212
cache.clear();
1313

@@ -41,7 +41,7 @@ test('SPLIT CACHE / LocalStorage', () => {
4141

4242
test('SPLIT CACHE / LocalStorage / Get Keys', () => {
4343
const cache = new SplitsCacheInLocal(fullSettings, new KeyBuilderCS('SPLITIO', 'user'));
44-
cache.validateCache();
44+
cache.validateCache(fullSettings);
4545

4646
cache.addSplit('lol1', something);
4747
cache.addSplit('lol2', somethingElse);
@@ -54,7 +54,7 @@ test('SPLIT CACHE / LocalStorage / Get Keys', () => {
5454

5555
test('SPLIT CACHE / LocalStorage / Add Splits', () => {
5656
const cache = new SplitsCacheInLocal(fullSettings, new KeyBuilderCS('SPLITIO', 'user'));
57-
cache.validateCache();
57+
cache.validateCache(fullSettings);
5858

5959
cache.addSplits([
6060
['lol1', something],
@@ -69,7 +69,7 @@ test('SPLIT CACHE / LocalStorage / Add Splits', () => {
6969

7070
test('SPLIT CACHE / LocalStorage / trafficTypeExists and ttcache tests', () => {
7171
const cache = new SplitsCacheInLocal(fullSettings, new KeyBuilderCS('SPLITIO', 'user'));
72-
cache.validateCache();
72+
cache.validateCache(fullSettings);
7373

7474
cache.addSplits([ // loop of addSplit
7575
['split1', splitWithUserTT],
@@ -108,7 +108,7 @@ test('SPLIT CACHE / LocalStorage / trafficTypeExists and ttcache tests', () => {
108108

109109
test('SPLIT CACHE / LocalStorage / killLocally', () => {
110110
const cache = new SplitsCacheInLocal(fullSettings, new KeyBuilderCS('SPLITIO', 'user'));
111-
cache.validateCache();
111+
cache.validateCache(fullSettings);
112112

113113
cache.addSplit('lol1', something);
114114
cache.addSplit('lol2', somethingElse);
@@ -142,7 +142,7 @@ test('SPLIT CACHE / LocalStorage / killLocally', () => {
142142

143143
test('SPLIT CACHE / LocalStorage / usesSegments', () => {
144144
const cache = new SplitsCacheInLocal(fullSettings, new KeyBuilderCS('SPLITIO', 'user'));
145-
cache.validateCache();
145+
cache.validateCache(fullSettings);
146146

147147
expect(cache.usesSegments()).toBe(true); // true initially, until data is synchronized
148148
cache.setChangeNumber(1); // to indicate that data has been synced.
@@ -174,7 +174,7 @@ test('SPLIT CACHE / LocalStorage / flag set cache tests', () => {
174174
}
175175
}
176176
}, new KeyBuilderCS('SPLITIO', 'user'));
177-
cache.validateCache();
177+
cache.validateCache(fullSettings);
178178

179179
const emptySet = new Set([]);
180180

@@ -216,7 +216,7 @@ test('SPLIT CACHE / LocalStorage / flag set cache tests', () => {
216216
// if FlagSets are not defined, it should store all FlagSets in memory.
217217
test('SPLIT CACHE / LocalStorage / flag set cache tests without filters', () => {
218218
const cache = new SplitsCacheInLocal(fullSettings, new KeyBuilderCS('SPLITIO', 'user'));
219-
cache.validateCache();
219+
cache.validateCache(fullSettings);
220220

221221
const emptySet = new Set([]);
222222

src/storages/inLocalStorage/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export function InLocalStorage(options: InLocalStorageOptions = {}): IStorageSyn
5555

5656
// @TODO implement
5757
validateCache() {
58-
return splits.validateCache(expirationTimestamp);
58+
return splits.validateCache(settings, expirationTimestamp);
5959
},
6060

6161
destroy() { },

0 commit comments

Comments
 (0)