FusionCache icon indicating copy to clipboard operation
FusionCache copied to clipboard

[FEATURE] FailSafe Customize Exception Handling

Open cmeyertons opened this issue 6 months ago • 7 comments

This is a fantastic library, and I sincerely appreciate all the work that has gone into this.

Problem

The fail-safe functionality is great, however there are certain scenarios where we want the fail-safe to trigger for some exceptions (but not all).

It's very common for ApiClients to throw exceptions when the status code is not successful, however we don't want the fail-safe to trigger for these kinds of known, bad requests.

An example of this behavior would involve only fail-safing on API responses with status codes >= 500, and letting 400-499 exceptions bubble up normally (400s, 404s, 401s, 403s, etc)

Solution

I would like the ability to configure the FailSafe mechanism with an optional Exception Filter.

Something like:

public class FusionCacheEntryOptions
{
     public Func<Exception, bool>? FailSafeExceptionFilter { get; set; }
}

Alternatives

Alternatively, we have to jump through hoops to adaptively turn off fail safing for specific error codes and cannot easily configure this behavior across numerous cache invocations (have to implement wrapper code, etc)

cmeyertons avatar Jul 31 '24 16:07 cmeyertons