Skip to content

Commit 94b432b

Browse files
committed
Push v1.0
1 parent 636d815 commit 94b432b

28 files changed

+1672
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Polly.Caching.IDistributedCache change log
2+
3+
## 1.0-RC
4+
5+
- Allows [Polly](https://github.com/App-vNext/Polly)'s [CachePolicy](https://github.com/App-vNext/Polly/wiki/Cache) to be used with [`Microsoft.Extensions.Caching.Distributed.IDistributedCache`](https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.caching.distributed.idistributedcache) [implementations](https://docs.microsoft.com/en-us/aspnet/core/performance/caching/distributed).
6+
- Release candidate

GitVersionConfig.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
next-version: 1.0.0

README.md

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,100 @@
11
# Polly.Caching.IDistributedCache
2-
Plug-in for the Polly Cache policy supporting Microsoft.Extensions.Caching.Distributed.IDistributedCache.
2+
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.
4+
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)
6+
7+
## What is Polly?
8+
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.
10+
11+
Polly is a member of the [.NET Foundation](https://www.dotnetfoundation.org/about)!
12+
13+
**Keep up to date with new feature announcements, tips & tricks, and other news through [www.thepollyproject.org](http://www.thepollyproject.org)**
14+
15+
![](https://raw.github.com/App-vNext/Polly/master/Polly-Logo.png)
16+
17+
## What is Polly.Caching.IDistributedCache?
18+
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).
20+
21+
# Installing Polly.Caching.IDistributedCache via NuGet
22+
23+
Install-Package Polly.Caching.IDistributedCache
24+
25+
You can install the Strongly Named version via:
26+
27+
Install-Package Polly.Caching.IDistributedCache-Signed
28+
29+
# Supported targets
30+
31+
Polly.Caching.IDistributedCache supports .NetStandard 1.1 and above.
32+
33+
## Dependencies
34+
35+
Polly.Caching.IDistributedCache requires:
36+
37+
+ [Polly](nuget.org/packages/polly) v5.4.0 or above.
38+
+ [Microsoft.Extensions.Caching.Abstractions](https://www.nuget.org/packages/Microsoft.Extensions.Caching.Abstractions/) v1.1.2 or above.
39+
40+
# How to use the Polly.Caching.IDistributedCache plugin
41+
42+
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
43+
44+
Assuming you have an instance `IDistributedCache distributedCache` in hand (perhaps just configured and instantiated, perhaps provided to local code by Dependency Injection):
45+
46+
```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+
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+
53+
// Or similarly for async executions returning string results:
54+
var cachePolicy = Policy.CacheAsync<string>(distributedCache.AsAsyncCacheProvider<string>, TimeSpan.FromMinutes(5));
55+
56+
// Or similarly for async executions returning byte[] results:
57+
var cachePolicy = Policy.CacheAsync<byte[]>(distributedCache.AsAsyncCacheProvider<byte[]>, TimeSpan.FromMinutes(5));
58+
59+
// You can also use ASP.NET Core's DistributedCacheEntryOptions for specifying cache item time-to-live, as shown below.
60+
// All time-to-live functionality represented by DistributedCacheEntryOptions is supported.
61+
DistributedCacheEntryOptions entryOptions = // ...
62+
var cachePolicy = Policy.CacheAsync<byte[]>(distributedCache.AsAsyncCacheProvider<byte[]>, entryOptions.AsTtlStrategy());
63+
64+
65+
```
66+
67+
Usage:
68+
69+
```csharp
70+
string productId = // ... from somewhere
71+
string productDescription = await cachePolicy.ExecuteAsync(() => getProductDescription(productId),
72+
new Context(productId) // productId will also be the cache key used in this execution.
73+
);
74+
```
75+
76+
For many more configuration options and usage examples of the main Polly `CachePolicy`, see the [main Polly readme](https://github.com/App-vNext/Polly#cache) and [deep doco on the Polly wiki](https://github.com/App-vNext/Polly/wiki/Cache). Additional overloads allow attaching delegates for cache errors, cache hits/misses etc, for logging and telemetry.
77+
78+
`CachePolicy` can of course also be combined with other policies in a [`PolicyWrap`](https://github.com/App-vNext/Polly/wiki/PolicyWrap).
79+
80+
# Release notes
81+
82+
For details of changes by release see the [change log](CHANGELOG.md).
83+
84+
85+
# Acknowledgements
86+
87+
* [@seanfarrow](https://github.com/seanfarrow) and [@reisenberger](https://github.com/reisenberger) - Initial caching architecture in the main Polly repo
88+
* [@reisenberger](https://github.com/reisenberger) - `IDistributedCache` implementation
89+
90+
# Instructions for Contributing
91+
92+
Please check out our [Wiki](https://github.com/App-vNext/Polly/wiki/Git-Workflow) for contributing guidelines. We are following the excellent GitHub Flow process, and would like to make sure you have all of the information needed to be a world-class contributor!
93+
94+
Since Polly is part of the .NET Foundation, we ask our contributors to abide by their [Code of Conduct](https://www.dotnetfoundation.org/code-of-conduct).
95+
96+
Also, we've stood up a [Slack](http://www.pollytalk.org) channel for easier real-time discussion of ideas and the general direction of Polly as a whole. Be sure to [join the conversation](http://www.pollytalk.org) today!
97+
98+
# License
99+
100+
Licensed under the terms of the [New BSD License](http://opensource.org/licenses/BSD-3-Clause)

build.bat

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@ECHO OFF
2+
PUSHD %~dp0
3+
PowerShell.exe -NoProfile -ExecutionPolicy Bypass -Command "& './build.ps1'"
4+
5+
PAUSE
6+

0 commit comments

Comments
 (0)