Skip to content

Commit 82e0648

Browse files
authored
Merge pull request #6 from App-vNext/v20dev
Release v2.0
2 parents 0b24c65 + 861f3dd commit 82e0648

31 files changed

+435
-211
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
# Polly.Caching.IDistributedCache change log
1+
# Polly.Caching.Distributed change log
2+
3+
## 2.0.0
4+
- Provide a single signed package only.
5+
- Update Polly to V6.0.1.
6+
- Support .net Standard 2.0.
7+
- Rename package, and change namespaces, from Polly.Caching.IDistributedCache to Polly.Caching.Distributed, to avoid clashes.
28

39
## 1.0-RC
410

GitVersionConfig.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
next-version: 1.0.0
1+
next-version: 2.0.0

README.md

Lines changed: 65 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,110 @@
1-
# Polly.Caching.IDistributedCache
1+
# Polly.Caching.Distributed
22

3-
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.
3+
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.
44

5-
[![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)
5+
[![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)
66

77
## What is Polly?
88

9-
[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.
9+
[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.
1010

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

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

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

17-
## What is Polly.Caching.IDistributedCache?
17+
## What is Polly.Caching.Distributed?
1818

19-
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).
19+
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).
2020

21-
# Installing Polly.Caching.IDistributedCache via NuGet
21+
# Installing Polly.Caching.Distributed via NuGet
2222

23-
Install-Package Polly.Caching.IDistributedCache
24-
25-
You can install the Strongly Named version via:
26-
27-
Install-Package Polly.Caching.IDistributedCache-Signed
23+
Install-Package Polly.Caching.Distributed
2824

2925
# Supported targets
3026

31-
Polly.Caching.IDistributedCache supports .NetStandard 1.1 and above.
27+
Polly.Caching.Distributed supports .NET Standard 1.1 and .NET Standard 2.0.
3228

3329
## Dependencies
3430

35-
Polly.Caching.IDistributedCache requires:
31+
Polly.Caching.IDistributedCache <v2.0 requires:
3632

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

40-
# How to use the Polly.Caching.IDistributedCache plugin
36+
Polly.Caching.Distributed >=v2.0 requires:
37+
38+
+ [Polly](nuget.org/packages/polly) v6.0.1 or above.
39+
+ [Microsoft.Extensions.Caching.Abstractions](https://www.nuget.org/packages/Microsoft.Extensions.Caching.Abstractions/) v2.0.2 or above.
40+
41+
# How to use the Polly.Caching.Distributed plugin
4142

4243
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`.
4344

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

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

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

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

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

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

6466

6567
```
6668

69+
Configuration via DI in ASPNET Core:
70+
71+
```csharp
72+
// 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.
73+
74+
// For example:
75+
public class Startup
76+
{
77+
public void ConfigureServices(IServiceCollection services)
78+
{
79+
services.AddDistributedRedisCache(options =>
80+
{
81+
options.Configuration = "localhost"; // or whatever
82+
options.InstanceName = "SampleInstance";
83+
});
84+
85+
services.AddSingleton<Polly.Caching.IAsyncCacheProvider<string>>(serviceProvider => serviceProvider.GetRequiredService<IDistributedCache>().AsAsyncCacheProvider<string>());
86+
87+
services.AddSingleton<Polly.Registry.IPolicyRegistry<string>, Polly.Registry.PolicyRegistry>((serviceProvider) =>
88+
{
89+
PolicyRegistry registry = new PolicyRegistry();
90+
registry.Add("myCachePolicy", Policy.CacheAsync<string>(serviceProvider.GetRequiredService<IAsyncCacheProvider<string>>(), TimeSpan.FromMinutes(5)));
91+
92+
return registry;
93+
});
94+
95+
// ...
96+
}
97+
}
98+
99+
// In a controller, inject the policyRegistry and retrieve the policy:
100+
// (magic string "myCachePolicy" hard-coded here only to keep the example simple)
101+
public MyController(IPolicyRegistry<string> policyRegistry)
102+
{
103+
var _cachePolicy = policyRegistry.Get<IAsyncPolicy<HttpResponseMessage>>("myCachePolicy");
104+
// ...
105+
}
106+
```
107+
67108
Usage:
68109

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

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

90132
# Instructions for Contributing
91133

0 commit comments

Comments
 (0)