ITokenCacheAccessContext Interface
public interface ITokenCacheAccessContext
Interface representing the context in which the token cache is accessed.
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
Method Summary
| Modifier and Type | Method and Description |
|---|---|
| abstract IAccount |
account()
Gets the account associated with the current cache access operation, if any. |
| abstract java.lang.String |
clientId()
Gets the client ID associated with the current cache access operation. |
| abstract boolean |
hasCacheChanged()
Indicates whether the cache was modified during this operation. |
|
abstract
IToken |
tokenCache()
Gets the token cache instance being accessed. |
Method Details
account
public abstract IAccount account()
Gets the account associated with the current cache access operation, if any.
This may be null for operations that are not specific to a user account, such as client credential flow token requests.
Returns:
clientId
public abstract String clientId()
Gets the client ID associated with the current cache access operation.
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.
Returns:
hasCacheChanged
public abstract boolean hasCacheChanged()
Indicates whether the cache was modified during this operation.
This is particularly useful in the ITokenCacheAccessAspect#afterCacheAccess method to determine whether the cache should be persisted. If no changes were made to the cache, applications can avoid unnecessary write operations.
Returns:
tokenCache
public abstract ITokenCache tokenCache()
Gets the token cache instance being accessed.
This can be used to read or modify the cache entries during a cache access operation.
Returns: