Skip to content

[Feature Request] Enable apps to decide what to do when the L2 cache fails (Retry) #1042

Closed

Description

Is your feature request related to a problem? Please describe.
Today, when the L2 cache fails, an error is logged, but given the L1 cache was able to proceed, we don't re-throw (think of Redis cache connection error)

Describe the solution you'd like

Have a new property in the MsalDistributedTokenCacheAdapterOptions, so that the application can handle the failure ?

 /// <summary>
 /// Callback offered to the app to be notified when the L2 cache fails.
 /// This way the app is given the possibility to act on the L2 cache,
 /// for instance, in the case of Redis, to reconnect. This is left to the application as it's
 /// the only one that knows about the real implementation of the L2 cache.
 /// The handler should return <c>true</c> if the cache should try again the operation, and
 /// <c>false</c> otherwise. When <c>true</c> is passed and the retry fails, an exception
 /// will be thrown.
 /// </summary>
 public Func<Exception, bool>? OnL2CacheFailure {get;set;}

Here is an example of how this would be hooked from the Startup.cs:

services.Configure<MsalDistributedTokenCacheAdapterOptions>(options =>
{
options.L1CacheSizeLimit = 10 * 1024 * 1024; // 10 Mb
options.OnL2CacheFailure = (ex) =>
{
  if (ex is StackExchange.Redis.RedisConnectionException)
  {
    // Attempt to act on the redis cache if at all possible?
    // Put here your reconnected code
    return true; // Retry
  } 
  return false;  // Don't retry.
 };
});

Describe alternatives you've considered
We could also decide of the behavior when it fails again on retry (we could be silent instead of throwing)

Activity

  1. jmprieur commented on Mar 4, 2021

    @jmprieur
    CollaboratorAuthor

    Advice from Henrik:

    • Look on stack overflow about the Redis connection issues; etc ..
    • henrikm (@henrik-me) will make sure we have the right people to help
  2. changed the title [-][Feature Request] Enable apps to decide what to do when the L2 cache fails[/-] [+][Feature Request] Enable apps to decide what to do when the L2 cache fails (Retry)[/+] on Mar 5, 2021
  3. jmprieur commented on Mar 8, 2021

    @jmprieur
    CollaboratorAuthor

    Re opening until it's released.

  4. jennyf19 commented on Mar 10, 2021

    @jennyf19
    Collaborator

    Included in 1.8.0 release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions