Table of Contents

Interface ITokenCache

Namespace
Microsoft.Identity.Client
Assembly
Microsoft.Identity.Client.dll

This is the interface that implements the public access to cache operations. With CacheV2, this should only be necessary if the caller is persisting the cache in their own store, since this will provide the serialize/deserialize and before/after notifications used in that scenario. See https://aka.ms/aka.ms/msal-net-token-cache-serialization

public interface ITokenCache
Extension Methods

Methods

SetAfterAccess(TokenCacheCallback)

Sets a delegate to be notified after any library method accesses the cache. This gives an option to the delegate to serialize a cache entry for the application and accounts specified in the TokenCacheNotificationArgs. See https://aka.ms/msal-net-token-cache-serialization. If you need async/task-based callbacks, please use SetAfterAccessAsync instead.

void SetAfterAccess(TokenCacheCallback afterAccess)

Parameters

afterAccess TokenCacheCallback

Delegate set in order to handle the cache serialization in the case where the HasStateChanged member of the cache is true

Remarks

In the case where the delegate is used to serialize the cache entirely (not just a row), it might want to call SerializeMsalV3()

SetAfterAccessAsync(Func<TokenCacheNotificationArgs, Task>)

Sets a delegate to be notified after any library method accesses the cache. This gives an option to the delegate to serialize a cache entry for the application and accounts specified in the TokenCacheNotificationArgs. See https://aka.ms/msal-net-token-cache-serialization. This provides the same functionality as SetAfterAccess but it provides for an async/task-based callback.

void SetAfterAccessAsync(Func<TokenCacheNotificationArgs, Task> afterAccess)

Parameters

afterAccess Func<TokenCacheNotificationArgs, Task>

Delegate set in order to handle the cache serialization in the case where the HasStateChanged member of the cache is true

Remarks

In the case where the delegate is used to serialize the cache entirely (not just a row), it might want to call SerializeMsalV3()

SetBeforeAccess(TokenCacheCallback)

Sets a delegate to be notified before any library method accesses the cache. This gives an option to the delegate to deserialize a cache entry for the application and accounts specified in the TokenCacheNotificationArgs. See https://aka.ms/msal-net-token-cache-serialization. If you need async/task-based callbacks, please use SetBeforeAccessAsync instead.

void SetBeforeAccess(TokenCacheCallback beforeAccess)

Parameters

beforeAccess TokenCacheCallback

Delegate set in order to handle the cache deserialization

Remarks

When the delegate is used to deserialize the cache, it might want to call DeserializeMsalV3(byte[], bool)

SetBeforeAccessAsync(Func<TokenCacheNotificationArgs, Task>)

Sets a delegate to be notified before any library method accesses the cache. This gives an option to the delegate to deserialize a cache entry for the application and accounts specified in the TokenCacheNotificationArgs. See https://aka.ms/msal-net-token-cache-serialization. This provides the same functionality as SetBeforeAccess but it provides for an async/task-based callback.

void SetBeforeAccessAsync(Func<TokenCacheNotificationArgs, Task> beforeAccess)

Parameters

beforeAccess Func<TokenCacheNotificationArgs, Task>

Delegate set in order to handle the cache deserialization

Remarks

In the case where the delegate is used to deserialize the cache, it might want to call DeserializeMsalV3(byte[], bool)

SetBeforeWrite(TokenCacheCallback)

Sets a delegate called before any library method writes to the cache. This gives an option to the delegate to reload the cache state from a row in database and lock that row. That database row can then be unlocked in the delegate registered with SetAfterAccess(TokenCacheCallback) If you need async/task-based callbacks, please use SetBeforeWriteAsync instead.

void SetBeforeWrite(TokenCacheCallback beforeWrite)

Parameters

beforeWrite TokenCacheCallback

Delegate set in order to prepare the cache serialization

SetBeforeWriteAsync(Func<TokenCacheNotificationArgs, Task>)

Sets a delegate called before any library method writes to the cache. This gives an option to the delegate to reload the cache state from a row in database and lock that row. That database row can then be unlocked in the delegate registered with SetAfterAccess(TokenCacheCallback) This provides the same functionality as SetBeforeWrite but it provides for an async/task-based callback.

void SetBeforeWriteAsync(Func<TokenCacheNotificationArgs, Task> beforeWrite)

Parameters

beforeWrite Func<TokenCacheNotificationArgs, Task>

Delegate set in order to prepare the cache serialization