You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/active-directory/develop/msal-net-token-cache-serialization.md
+6-3Lines changed: 6 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,7 @@ The recommendation is:
32
32
- Otherwise, if you want to use an in-memory cache
33
33
- If you're only using `AcquireTokenForClient`:
34
34
- 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.
36
36
- 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)
37
37
- 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.
@@ -247,6 +248,8 @@ You can specify that you don't want to have any token cache serialization (using
247
248
.Build();
248
249
```
249
250
251
+
`WithCacheOptions(CacheOptions.EnableSharedCacheOptions)` makestheinternalMSALtokencachesharedbetweendifferentMSALclientapplicationinstances. Sharingatokencacheisfasterthanusinganytokencacheserialization, buttheinternalin-memorytokencachedoesn'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'tusesharedcacheandcacheserializationtogether.
252
+
250
253
#### In memory token cache
251
254
252
255
Inmemorytokencacheserializationisgreatinsamples. It'salsogoodinproductionapplicationsifyouonlyrequestapptokens (`AcquireTokenForClient`), providedyoudon't mind if the token cache is lost when the web app is restarted. It'snotrecommendedinproductionifyourequestusertokens (`AcquireTokenByAuthorizationCode`, `AcquireTokenSilent`, `AcquireTokenOnBehalfOf`)
0 commit comments