Skip to content

Commit b4e498c

Browse files
authored
Stop looking in localStorage for temporary cache (#8579)
This pull request simplifies the behavior of the `getTemporaryCache` method in `BrowserCacheManager` by removing legacy fallback logic and updates the related unit tests accordingly. The main focus is to ensure that temporary cache retrieval is streamlined and no longer checks local storage for items set by old versions. Fixes #8577 **Browser cache logic simplification:** - [`BrowserCacheManager.ts`](diffhunk://#diff-9fe0cda3d1225c92740f98cfd73639c5db18bf24234c273756a855e5b48adae2R1904-R1906): Removed fallback logic in `getTemporaryCache` that previously checked `localStorage` for temporary cache items if not found in session/memory storage. The method now only checks the intended temporary cache storage. Added a trace log for method invocation. **Test updates:** - [`BrowserCacheManager.spec.ts`](diffhunk://#diff-1f474f3b5ffedcb4da969f60d720532be75a02c6d91e65b7d1e3c107b0a4f13dL1878-L1900): Removed the test that verified fallback to `localStorage` in `getTemporaryCache`, as this behavior is no longer supported. --------- Co-authored-by: -g <-g>
1 parent 1b261b4 commit b4e498c

3 files changed

Lines changed: 12 additions & 46 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Stop looking in localStorage for temporary cache [#8579](https://github.com/AzureAD/microsoft-authentication-library-for-js/pull/8579)",
4+
"packageName": "@azure/msal-browser",
5+
"email": "-g",
6+
"dependentChangeType": "patch"
7+
}

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

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,30 +1901,12 @@ export class BrowserCacheManager extends CacheManager {
19011901
correlationId: string,
19021902
generateKey?: boolean
19031903
): string | null {
1904+
this.logger.trace(
1905+
"BrowserCacheManager.getTemporaryCache called",
1906+
correlationId
1907+
);
19041908
const key = generateKey ? this.generateCacheKey(cacheKey) : cacheKey;
1905-
const value = this.temporaryCacheStorage.getItem(key);
1906-
if (!value) {
1907-
// If temp cache item not found in session/memory, check local storage for items set by old versions
1908-
if (
1909-
this.cacheConfig.cacheLocation ===
1910-
BrowserCacheLocation.LocalStorage
1911-
) {
1912-
const item = this.browserStorage.getItem(key);
1913-
if (item) {
1914-
this.logger.trace(
1915-
"BrowserCacheManager.getTemporaryCache: Temporary cache item found in local storage",
1916-
correlationId
1917-
);
1918-
return item;
1919-
}
1920-
}
1921-
this.logger.trace(
1922-
"BrowserCacheManager.getTemporaryCache: No cache item found in local storage",
1923-
correlationId
1924-
);
1925-
return null;
1926-
}
1927-
return value;
1909+
return this.temporaryCacheStorage.getItem(key);
19281910
}
19291911

19301912
/**

lib/msal-browser/test/cache/BrowserCacheManager.spec.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,29 +1875,6 @@ describe("BrowserCacheManager tests", () => {
18751875
expect(window.sessionStorage.getItem(msalCacheKey2)).toBe(cacheVal);
18761876
});
18771877

1878-
it("getTemporaryCache falls back to local storage if not found in session/memory storage", () => {
1879-
const testTempItemKey = "test-temp-item-key";
1880-
const testTempItemValue = "test-temp-item-value";
1881-
window.localStorage.setItem(testTempItemKey, testTempItemValue);
1882-
browserLocalStorage = new BrowserCacheManager(
1883-
TEST_CONFIG.MSAL_CLIENT_ID,
1884-
{
1885-
...cacheConfig,
1886-
cacheLocation: BrowserCacheLocation.LocalStorage,
1887-
},
1888-
browserCrypto,
1889-
logger,
1890-
new StubPerformanceClient(),
1891-
new EventHandler()
1892-
);
1893-
expect(
1894-
browserLocalStorage.getTemporaryCache(
1895-
testTempItemKey,
1896-
TEST_CONFIG.CORRELATION_ID
1897-
)
1898-
).toBe(testTempItemValue);
1899-
});
1900-
19011878
it("setItem", () => {
19021879
window.sessionStorage.setItem(msalCacheKey, cacheVal);
19031880
window.localStorage.setItem(msalCacheKey2, cacheVal);

0 commit comments

Comments
 (0)