Include Storage Location In Fake Cache Key (#8203)

This commit is contained in:
Justin Baur 2024-03-05 11:30:40 -06:00 committed by GitHub
parent 7bb24d5fad
commit c9b5125f74
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 7 deletions

View File

@ -32,7 +32,8 @@ export class FakeGlobalStateProvider implements GlobalStateProvider {
states: Map<string, GlobalState<unknown>> = new Map(); states: Map<string, GlobalState<unknown>> = new Map();
get<T>(keyDefinition: KeyDefinition<T>): GlobalState<T> { get<T>(keyDefinition: KeyDefinition<T>): GlobalState<T> {
this.mock.get(keyDefinition); 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) { if (result == null) {
let fake: FakeGlobalState<T>; let fake: FakeGlobalState<T>;
@ -44,10 +45,10 @@ export class FakeGlobalStateProvider implements GlobalStateProvider {
} }
fake.keyDefinition = keyDefinition; fake.keyDefinition = keyDefinition;
result = fake; result = fake;
this.states.set(keyDefinition.fullName, result); this.states.set(cacheKey, result);
result = new FakeGlobalState<T>(); result = new FakeGlobalState<T>();
this.states.set(keyDefinition.fullName, result); this.states.set(cacheKey, result);
} }
return result as GlobalState<T>; return result as GlobalState<T>;
} }
@ -76,7 +77,8 @@ export class FakeSingleUserStateProvider implements SingleUserStateProvider {
if (keyDefinition instanceof KeyDefinition) { if (keyDefinition instanceof KeyDefinition) {
keyDefinition = UserKeyDefinition.fromBaseKeyDefinition(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) { if (result == null) {
let fake: FakeSingleUserState<T>; let fake: FakeSingleUserState<T>;
@ -88,7 +90,7 @@ export class FakeSingleUserStateProvider implements SingleUserStateProvider {
} }
fake.keyDefinition = keyDefinition; fake.keyDefinition = keyDefinition;
result = fake; result = fake;
this.states.set(`${keyDefinition.fullName}_${userId}`, result); this.states.set(cacheKey, result);
} }
return result as SingleUserState<T>; return result as SingleUserState<T>;
} }
@ -119,7 +121,8 @@ export class FakeActiveUserStateProvider implements ActiveUserStateProvider {
if (keyDefinition instanceof KeyDefinition) { if (keyDefinition instanceof KeyDefinition) {
keyDefinition = UserKeyDefinition.fromBaseKeyDefinition(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) { if (result == null) {
// Look for established mock // Look for established mock
@ -129,7 +132,7 @@ export class FakeActiveUserStateProvider implements ActiveUserStateProvider {
result = new FakeActiveUserState<T>(this.accountService); result = new FakeActiveUserState<T>(this.accountService);
} }
result.keyDefinition = keyDefinition; result.keyDefinition = keyDefinition;
this.states.set(keyDefinition.fullName, result); this.states.set(cacheKey, result);
} }
return result as ActiveUserState<T>; return result as ActiveUserState<T>;
} }