Skip to content

Add Polly policies to your IDistributedCache interface to handle cache downtimes

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

darthfabar/DistributedCachePollyDecorator

DistributedCachePollyDecorator

GitHub Actions Status

GitHub Actions Build History

What Does This Package Do?

With this package you can inject Polly policy behaviours to the IDistributedCache interface. Right now it enables you to have a circuitbreaker policy that enables you to fail fast in case you Redis is down or your app runs into connection errors.

How to use the package:

Just add a 'AddDistributedCacheDecorator' call in your Startup.cs / any other place where you do your registrations

	public void ConfigureServices(IServiceCollection services)
	{

		services.AddControllers();

		// your settings for Redis
		services.AddStackExchangeRedisCache(options =>
		{
			options.Configuration = "localhost:6379,allowAdmin=true,DefaultDatabase=1";
		});

		// Decorate the inferface with a simple circuit breaker
		services.AddDistributedCacheDecorator(new CircuitBreakerSettings()
		{
			DurationOfBreak = TimeSpan.FromMinutes(5),
			ExceptionsAllowedBeforeBreaking = 2
		});

		// OR decorate it with an advanced one: (don't add both)
		services.AddDistributedCacheDecorator(new CircuitBreakerAdvancedSettings()
		{
			DurationOfBreak = TimeSpan.FromMinutes(5),
			FailureThreshold = 0.5,
			MinimumThroughput = 100,
			SamplingDuration = TimeSpan.FromMinutes(2)
		});
	}

Install Package

dotnet add package DistributedCachePollyDecorator --version 1.0.0

Or go to https://www.nuget.org/packages/DistributedCachePollyDecorator/