public interface ITokenCacheAccessContext
When MSAL accesses the token cache (before or after), it provides an instance of this interface
to the application through ITokenCacheAccessAspect methods. This allows the application
to get information about the cache access operation being performed, such as which client and account
are involved, and whether the operation modified the cache.
This context is particularly useful for applications implementing token cache serialization and persistence strategies, as it helps determine when the cache should be loaded from or saved to persistent storage.
For more details, see https://aka.ms/msal4j-token-cache
| Modifier and Type | Method and Description |
|---|---|
IAccount |
account()
Gets the account associated with the current cache access operation, if any.
|
String |
clientId()
Gets the client ID associated with the current cache access operation.
|
boolean |
hasCacheChanged()
Indicates whether the cache was modified during this operation.
|
ITokenCache |
tokenCache()
Gets the token cache instance being accessed.
|
ITokenCache tokenCache()
This can be used to read or modify the cache entries during a cache access operation.
ITokenCache instance that is being accessed.String clientId()
This identifies which client application (registered in Azure AD) is performing the cache access. In multi-tenant or multi-client scenarios, applications may want to partition their token cache by client ID.
IAccount account()
This may be null for operations that are not specific to a user account, such as client credential flow token requests.
IAccount instance related to this cache access, or null if
the operation is not account-specific.boolean hasCacheChanged()
This is particularly useful in the ITokenCacheAccessAspect.afterCacheAccess(com.microsoft.aad.msal4j.ITokenCacheAccessContext) method
to determine whether the cache should be persisted. If no changes were made to the cache,
applications can avoid unnecessary write operations.
Copyright © 2013–2025. All rights reserved.