Skip to content

Commit 73388fa

Browse files
authored
Merge pull request #83982 from bgavrilMS/patch-9
Update msal-net-token-cache-serialization.md
2 parents eda9742 + 1e49604 commit 73388fa

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

articles/active-directory/develop/msal-net-token-cache-serialization.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ The recommendation is:
3232
- Otherwise, if you want to use an in-memory cache
3333
- If you're only using `AcquireTokenForClient`:
3434
- Either reuse the confidential client application instance and don’t add a serializer,
35-
- Or new-up a new confidential client application and enable the [shared cache option](msal-net-token-cache-serialization.md?tabs=aspnet#no-token-cache-serialization) . This cache is faster as it's not serialized, however, the memory will grow as tokens are cached. The number of tokens is equal to the number of tenants times the number of downstream APIs. An app token is about 2KB in size. It's great for development, or if you have few users. If you need eviction, see next bullet point.
35+
- Or new-up a new confidential client application and enable the [shared cache option](msal-net-token-cache-serialization.md?tabs=aspnet#no-token-cache-serialization). This cache is faster as it's not serialized, however, the memory will grow as tokens are cached. The number of tokens is equal to the number of tenants times the number of downstream APIs. An app token is about 2KB in size. It's great for development, or if you have few users. If you need eviction, see next bullet point.
3636
- If you want to use an in-memory token cache and control its size and eviction policies, use the [Microsoft.Identity.Web in memory cache option](msal-net-token-cache-serialization.md?tabs=aspnet#in-memory-token-cache-1)
3737
- If you build an SDK and want to write your own token cache serializer for confidential client applications, inherit from [Microsoft.Identity.Web.MsalAsbtractTokenCacheProvider](https://github.com/AzureAD/microsoft-identity-web/blob/master/src/Microsoft.Identity.Web.TokenCache/MsalAbstractTokenCacheProvider.cs) and override the `WriteCacheBytesAsync` and `ReadCacheBytesAsync` methods.
3838

@@ -230,9 +230,10 @@ public static async Task<AuthenticationResult> GetTokenAsync(string clientId, X5
230230

231231
Instead of `app.AddInMemoryTokenCache();` you can use different caching serialization technologies, including no serialization, in memory, and distributed token cache storage provided by .NET.
232232

233-
#### No token cache serialization
233+
<a id="no-token-cache-serialization"></a>
234+
#### Token cache without serialization
234235

235-
You can specify that you don't want to have any token cache serialization (using the MSAL.NET internal cache), if you:
236+
You can specify that you don't want to have any token cache serialization and instead rely on the MSAL.NET internal cache:
236237
- Use `.WithCacheOptions(CacheOptions.EnableSharedCacheOptions)` when you build the application.
237238
- Don't add any serializer.
238239

@@ -247,6 +248,8 @@ You can specify that you don't want to have any token cache serialization (using
247248
.Build();
248249
```
249250

251+
`WithCacheOptions(CacheOptions.EnableSharedCacheOptions)` makes the internal MSAL token cache shared between different MSAL client application instances. Sharing a token cache is faster than using any token cache serialization, but the internal in-memory token cache doesn't have eviction policies. Existing tokens will be refreshed in place, but fetching tokens for different users, tenants, and resources makes the cache grow accordingly. If you use this approach and have a large number of users or tenants, make sure you monitor the memory footprint. If the memory footprint becomes an issue, consider enabling token cache serialization, which might reduce the internal cache size. Also be aware that currently, you can't use shared cache and cache serialization together.
252+
250253
#### In memory token cache
251254

252255
In memory token cache serialization is great in samples. It's also good in production applications if you only request app tokens (`AcquireTokenForClient`), provided you don't mind if the token cache is lost when the web app is restarted. It's not recommended in production if you request user tokens (`AcquireTokenByAuthorizationCode`, `AcquireTokenSilent`, `AcquireTokenOnBehalfOf`)

0 commit comments

Comments
 (0)