Skip to content

Commit

Permalink
Merge pull request #6 from App-vNext/v20dev
Browse files Browse the repository at this point in the history
Release v2.0
  • Loading branch information
joelhulen authored Jun 14, 2018
2 parents 0b24c65 + 861f3dd commit 82e0648
Show file tree
Hide file tree
Showing 31 changed files with 435 additions and 211 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Polly.Caching.IDistributedCache change log
# Polly.Caching.Distributed change log

## 2.0.0
- Provide a single signed package only.
- Update Polly to V6.0.1.
- Support .net Standard 2.0.
- Rename package, and change namespaces, from Polly.Caching.IDistributedCache to Polly.Caching.Distributed, to avoid clashes.

## 1.0-RC

Expand Down
2 changes: 1 addition & 1 deletion GitVersionConfig.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
next-version: 1.0.0
next-version: 2.0.0
88 changes: 65 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,69 +1,110 @@
# Polly.Caching.IDistributedCache
# Polly.Caching.Distributed

This repo contains the `Microsoft.Extensions.Caching.Distributed.IDistributedCache` plugin for the [Polly](https://github.com/App-vNext/Polly) [Cache policy](https://github.com/App-vNext/Polly/wiki/Cache). It targets .NET Standard 1.1.
This repo contains the `Microsoft.Extensions.Caching.Distributed.IDistributedCache` provider for the [Polly](https://github.com/App-vNext/Polly) [Cache policy](https://github.com/App-vNext/Polly/wiki/Cache). The current version targets .NET Standard 1.1 and .NET Standard 2.0.

[![NuGet version](https://badge.fury.io/nu/Polly.Caching.IDistributedCache.svg)](https://badge.fury.io/nu/Polly.Caching.IDistributedCache) [![Build status](https://ci.appveyor.com/api/projects/status/pgd89nfdr9u4ig8m?svg=true)](https://ci.appveyor.com/project/joelhulen/polly-caching-IDistributedCache) [![Slack Status](http://www.pollytalk.org/badge.svg)](http://www.pollytalk.org)
[![NuGet version](https://badge.fury.io/nu/Polly.Caching.Distributed.svg)](https://badge.fury.io/nu/Polly.Caching.Distributed) [![Build status](https://ci.appveyor.com/api/projects/status/pgd89nfdr9u4ig8m?svg=true)](https://ci.appveyor.com/project/joelhulen/polly-caching-Distributed) [![Slack Status](http://www.pollytalk.org/badge.svg)](http://www.pollytalk.org)

## What is Polly?

[Polly](https://github.com/App-vNext/Polly) is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, Cache aside and Fallback in a fluent and thread-safe manner. Polly targets .NET 4.0, .NET 4.5 and .NET Standard 1.1.
[Polly](https://github.com/App-vNext/Polly) is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, Cache aside and Fallback in a fluent and thread-safe manner. Polly targets .NET Standard 1.1 and .NET Standard 2.0.

Polly is a member of the [.NET Foundation](https://www.dotnetfoundation.org/about)!
Polly is a member of the [.NET Foundation](https://www.dotnetfoundation.org/about).

**Keep up to date with new feature announcements, tips & tricks, and other news through [www.thepollyproject.org](http://www.thepollyproject.org)**

![](https://raw.github.com/App-vNext/Polly/master/Polly-Logo.png)

## What is Polly.Caching.IDistributedCache?
## What is Polly.Caching.Distributed?

This project, Polly.Caching.IDistributedCache, allows you to use Polly's `CachePolicy` with [implementations of](https://docs.microsoft.com/en-us/aspnet/core/performance/caching/distributed) .Net Standard's [`IDistributedCache`](https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.caching.distributed.idistributedcache).
This project, Polly.Caching.Distributed, allows you to use Polly's `CachePolicy` with [implementations of](https://docs.microsoft.com/en-us/aspnet/core/performance/caching/distributed) .Net Standard's [`IDistributedCache`](https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.caching.distributed.idistributedcache).

# Installing Polly.Caching.IDistributedCache via NuGet
# Installing Polly.Caching.Distributed via NuGet

Install-Package Polly.Caching.IDistributedCache

You can install the Strongly Named version via:

Install-Package Polly.Caching.IDistributedCache-Signed
Install-Package Polly.Caching.Distributed

# Supported targets

Polly.Caching.IDistributedCache supports .NetStandard 1.1 and above.
Polly.Caching.Distributed supports .NET Standard 1.1 and .NET Standard 2.0.

## Dependencies

Polly.Caching.IDistributedCache requires:
Polly.Caching.IDistributedCache <v2.0 requires:

+ [Polly](nuget.org/packages/polly) v5.4.0 or above.
+ [Microsoft.Extensions.Caching.Abstractions](https://www.nuget.org/packages/Microsoft.Extensions.Caching.Abstractions/) v1.1.2 or above.

# How to use the Polly.Caching.IDistributedCache plugin
Polly.Caching.Distributed >=v2.0 requires:

+ [Polly](nuget.org/packages/polly) v6.0.1 or above.
+ [Microsoft.Extensions.Caching.Abstractions](https://www.nuget.org/packages/Microsoft.Extensions.Caching.Abstractions/) v2.0.2 or above.

# How to use the Polly.Caching.Distributed plugin

These notes assume you are familiar with using the .Net Standard `IDistributedCache` implementations. For information, see: https://docs.microsoft.com/en-us/aspnet/core/performance/caching/distributed . As described on that page, Microsoft provide a Redis implementation and an SQL server implementation for `IDistributedCache`.

Assuming you have an instance `IDistributedCache distributedCache` in hand (perhaps just configured and instantiated, perhaps provided to local code by Dependency Injection):


```csharp
// Create a Polly cache policy for caching string results, using that `IDistributedCache` instance.
var cachePolicy = Policy.Cache<string>(distributedCache.AsSyncCacheProvider<string>, TimeSpan.FromMinutes(5));
// Create a Polly cache policy for caching string results, using that IDistributedCache instance.
var cachePolicy = Policy.Cache<string>(distributedCache.AsSyncCacheProvider<string>(), TimeSpan.FromMinutes(5));

// Create a Polly cache policy for caching byte[] results, using that `IDistributedCache` instance.
var cachePolicy = Policy.Cache<byte[]>(distributedCache.AsSyncCacheProvider<byte[]>, TimeSpan.FromMinutes(5));
// Create a Polly cache policy for caching byte[] results, using that IDistributedCache instance.
var cachePolicy = Policy.Cache<byte[]>(distributedCache.AsSyncCacheProvider<byte[]>(), TimeSpan.FromMinutes(5));

// Or similarly for async executions returning string results:
var cachePolicy = Policy.CacheAsync<string>(distributedCache.AsAsyncCacheProvider<string>, TimeSpan.FromMinutes(5));
var cachePolicy = Policy.CacheAsync<string>(distributedCache.AsAsyncCacheProvider<string>(), TimeSpan.FromMinutes(5));

// Or similarly for async executions returning byte[] results:
var cachePolicy = Policy.CacheAsync<byte[]>(distributedCache.AsAsyncCacheProvider<byte[]>, TimeSpan.FromMinutes(5));
var cachePolicy = Policy.CacheAsync<byte[]>(distributedCache.AsAsyncCacheProvider<byte[]>(), TimeSpan.FromMinutes(5));

// You can also use ASP.NET Core's DistributedCacheEntryOptions for specifying cache item time-to-live, as shown below.
// All time-to-live functionality represented by DistributedCacheEntryOptions is supported.
DistributedCacheEntryOptions entryOptions = // ...
var cachePolicy = Policy.CacheAsync<byte[]>(distributedCache.AsAsyncCacheProvider<byte[]>, entryOptions.AsTtlStrategy());
var cachePolicy = Policy.CacheAsync<byte[]>(distributedCache.AsAsyncCacheProvider<byte[]>(), entryOptions.AsTtlStrategy());


```

Configuration via DI in ASPNET Core:

```csharp
// In this example we choose to pass a whole PolicyRegistry by dependency injection rather than the individual policy, on the assumption the webapp will probably use multiple policies across the app.
// For example:
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddDistributedRedisCache(options =>
{
options.Configuration = "localhost"; // or whatever
options.InstanceName = "SampleInstance";
});

services.AddSingleton<Polly.Caching.IAsyncCacheProvider<string>>(serviceProvider => serviceProvider.GetRequiredService<IDistributedCache>().AsAsyncCacheProvider<string>());

services.AddSingleton<Polly.Registry.IPolicyRegistry<string>, Polly.Registry.PolicyRegistry>((serviceProvider) =>
{
PolicyRegistry registry = new PolicyRegistry();
registry.Add("myCachePolicy", Policy.CacheAsync<string>(serviceProvider.GetRequiredService<IAsyncCacheProvider<string>>(), TimeSpan.FromMinutes(5)));

return registry;
});

// ...
}
}

// In a controller, inject the policyRegistry and retrieve the policy:
// (magic string "myCachePolicy" hard-coded here only to keep the example simple)
public MyController(IPolicyRegistry<string> policyRegistry)
{
var _cachePolicy = policyRegistry.Get<IAsyncPolicy<HttpResponseMessage>>("myCachePolicy");
// ...
}
```

Usage:

```csharp
Expand All @@ -86,6 +127,7 @@ For details of changes by release see the [change log](CHANGELOG.md).

* [@seanfarrow](https://github.com/seanfarrow) and [@reisenberger](https://github.com/reisenberger) - Initial caching architecture in the main Polly repo
* [@reisenberger](https://github.com/reisenberger) - `IDistributedCache` implementation
* [@seanfarrow](https://github.com/seanfarrow) - v2.0 update to Signed packages only to correspond with Polly v6.0.1

# Instructions for Contributing

Expand Down
Loading

0 comments on commit 82e0648

Please sign in to comment.