Skip to content

Commit 3da2e57

Browse files
committed
Cache save/delete/lookup moved to platform specific implementation
1 parent 533a907 commit 3da2e57

File tree

9 files changed

+490
-183
lines changed

9 files changed

+490
-183
lines changed

lib/msal-browser/src/cache/BrowserStorage.ts

+31-1
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,13 @@ export class BrowserStorage implements ICacheStorage {
152152
* Will also clear the cookie item if storeAuthStateInCookie is set to true.
153153
* @param key
154154
*/
155-
removeItem(key: string): void {
155+
removeItem(key: string): boolean {
156156
const msalKey = this.generateCacheKey(key);
157157
this.windowStorage.removeItem(msalKey);
158158
if (this.cacheConfig.storeAuthStateInCookie) {
159159
this.clearItemCookie(msalKey);
160160
}
161+
return true;
161162
}
162163

163164
/**
@@ -271,4 +272,33 @@ export class BrowserStorage implements ICacheStorage {
271272
setCache(): void {
272273
// sets nothing
273274
}
275+
276+
/**
277+
* Dummy implementation for interface compat - will change after BrowserCacheMigration
278+
* @param key
279+
* @param value
280+
* @param type
281+
*/
282+
setItemInMemory(key: string, value: object, type?: string): void {
283+
if (key && value && type)
284+
return;
285+
}
286+
287+
/**
288+
* Dummy implementation for interface compat - will change after BrowserCacheMigration
289+
* @param key
290+
* @param type
291+
*/
292+
getItemFromMemory(key: string, type?: string): object {
293+
return key && type ? {} : {};
294+
};
295+
296+
/**
297+
* Dummy implementation for interface compat - will change after BrowserCacheMigration
298+
* @param key
299+
* @param type
300+
*/
301+
removeItemFromMemory(key: string, type?: string): boolean {
302+
return key && type ? true : false;
303+
};
274304
}

lib/msal-common/src/cache/ICacheStorage.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,40 @@ export interface ICacheStorage {
2929
*/
3030
setItem(key: string, value: string): void;
3131

32+
/**
33+
* Function to set item in Memory
34+
* @param key
35+
* @param value
36+
* @param type
37+
*/
38+
setItemInMemory(key: string, value: object, type?: string): void;
39+
3240
/**
3341
* Function which retrieves item from cache.
3442
* @param key
3543
*/
3644
getItem(key: string): string;
3745

3846
/**
39-
* Function which removes item from cache.
47+
* Function to get an item from memory
48+
* @param key
49+
* @param type
50+
*/
51+
getItemFromMemory(key: string, type?: string): object;
52+
53+
/**
54+
* Function to remove an item from cache given its key.
4055
* @param key
4156
*/
4257
removeItem(key: string): boolean;
4358

59+
/**
60+
* Function to remove an item from memory given its key
61+
* @param key
62+
* @param type
63+
*/
64+
removeItemFromMemory(key: string, type?: string): boolean;
65+
4466
/**
4567
* Function which returns boolean whether cache contains a specific key.
4668
* @param key

lib/msal-common/src/config/ClientConfiguration.ts

+12
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ const DEFAULT_STORAGE_IMPLEMENTATION: ICacheStorage = {
125125
const notImplErr = "Storage interface - getItem() has not been implemented for the cacheStorage interface.";
126126
throw AuthError.createUnexpectedError(notImplErr);
127127
},
128+
getItemFromMemory: (): object => {
129+
const notImplErr = "Storage interface - getItemFromMemory() has not been implemented for the cacheStorage interface.";
130+
throw AuthError.createUnexpectedError(notImplErr);
131+
},
128132
getKeys: (): string[] => {
129133
const notImplErr = "Storage interface - getKeys() has not been implemented for the cacheStorage interface.";
130134
throw AuthError.createUnexpectedError(notImplErr);
@@ -133,10 +137,18 @@ const DEFAULT_STORAGE_IMPLEMENTATION: ICacheStorage = {
133137
const notImplErr = "Storage interface - removeItem() has not been implemented for the cacheStorage interface.";
134138
throw AuthError.createUnexpectedError(notImplErr);
135139
},
140+
removeItemFromMemory: () => {
141+
const notImplErr = "Storage interface - removeItemFromMemory() has not been implemented for the cacheStorage interface.";
142+
throw AuthError.createUnexpectedError(notImplErr);
143+
},
136144
setItem: () => {
137145
const notImplErr = "Storage interface - setItem() has not been implemented for the cacheStorage interface.";
138146
throw AuthError.createUnexpectedError(notImplErr);
139147
},
148+
setItemInMemory: () => {
149+
const notImplErr = "Storage interface - setItemInMemory() has not been implemented for the cacheStorage interface.";
150+
throw AuthError.createUnexpectedError(notImplErr);
151+
},
140152
getCache: (): InMemoryCache => {
141153
const notImplErr = "Storage interface - getCache() has not been implemented for the cacheStorage interface.";
142154
throw AuthError.createUnexpectedError(notImplErr);

lib/msal-common/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export { ClientAuthError, ClientAuthErrorMessage } from "./error/ClientAuthError
5050
export { ClientConfigurationError, ClientConfigurationErrorMessage } from "./error/ClientConfigurationError";
5151
// Constants and Utils
5252
export {
53-
Constants, PromptValue, TemporaryCacheKeys, PersistentCacheKeys, Prompt, ResponseMode
53+
Constants, PromptValue, TemporaryCacheKeys, PersistentCacheKeys, Prompt, ResponseMode, CacheSchemaType, CredentialType
5454
} from "./utils/Constants";
5555
export { StringUtils } from "./utils/StringUtils";
5656
export { StringDict } from "./utils/MsalTypes";

0 commit comments

Comments
 (0)