Skip to content

Commit

Permalink
Include Storage Location In Fake Cache Key (#8203)
Browse files Browse the repository at this point in the history
  • Loading branch information
justindbaur authored Mar 5, 2024
1 parent 7bb24d5 commit c9b5125
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions libs/common/spec/fake-state-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export class FakeGlobalStateProvider implements GlobalStateProvider {
states: Map<string, GlobalState<unknown>> = new Map();
get<T>(keyDefinition: KeyDefinition<T>): GlobalState<T> {
this.mock.get(keyDefinition);
let result = this.states.get(keyDefinition.fullName);
const cacheKey = `${keyDefinition.fullName}_${keyDefinition.stateDefinition.defaultStorageLocation}`;
let result = this.states.get(cacheKey);

if (result == null) {
let fake: FakeGlobalState<T>;
Expand All @@ -44,10 +45,10 @@ export class FakeGlobalStateProvider implements GlobalStateProvider {
}
fake.keyDefinition = keyDefinition;
result = fake;
this.states.set(keyDefinition.fullName, result);
this.states.set(cacheKey, result);

result = new FakeGlobalState<T>();
this.states.set(keyDefinition.fullName, result);
this.states.set(cacheKey, result);
}
return result as GlobalState<T>;
}
Expand Down Expand Up @@ -76,7 +77,8 @@ export class FakeSingleUserStateProvider implements SingleUserStateProvider {
if (keyDefinition instanceof KeyDefinition) {
keyDefinition = UserKeyDefinition.fromBaseKeyDefinition(keyDefinition);
}
let result = this.states.get(`${keyDefinition.fullName}_${userId}`);
const cacheKey = `${keyDefinition.fullName}_${keyDefinition.stateDefinition.defaultStorageLocation}_${userId}`;
let result = this.states.get(cacheKey);

if (result == null) {
let fake: FakeSingleUserState<T>;
Expand All @@ -88,7 +90,7 @@ export class FakeSingleUserStateProvider implements SingleUserStateProvider {
}
fake.keyDefinition = keyDefinition;
result = fake;
this.states.set(`${keyDefinition.fullName}_${userId}`, result);
this.states.set(cacheKey, result);
}
return result as SingleUserState<T>;
}
Expand Down Expand Up @@ -119,7 +121,8 @@ export class FakeActiveUserStateProvider implements ActiveUserStateProvider {
if (keyDefinition instanceof KeyDefinition) {
keyDefinition = UserKeyDefinition.fromBaseKeyDefinition(keyDefinition);
}
let result = this.states.get(keyDefinition.fullName);
const cacheKey = `${keyDefinition.fullName}_${keyDefinition.stateDefinition.defaultStorageLocation}`;
let result = this.states.get(cacheKey);

if (result == null) {
// Look for established mock
Expand All @@ -129,7 +132,7 @@ export class FakeActiveUserStateProvider implements ActiveUserStateProvider {
result = new FakeActiveUserState<T>(this.accountService);
}
result.keyDefinition = keyDefinition;
this.states.set(keyDefinition.fullName, result);
this.states.set(cacheKey, result);
}
return result as ActiveUserState<T>;
}
Expand Down

0 comments on commit c9b5125

Please sign in to comment.