Skip to content

Commit cf8bfb5

Browse files
authored
Merge pull request #7 from reisenberger/master
Target Polly v5.4; add RC doco
2 parents ea7e66f + ffc56d4 commit cf8bfb5

File tree

6 files changed

+72
-11
lines changed

6 files changed

+72
-11
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Polly.Caching.MemoryCache change log
22

3+
## 1.0-RC
4+
5+
- Upgrade to Polly v5.4.0
6+
- Correctly state RC dependency (Polly v5.4.0)
7+
38
## 0.2-beta
49

510
- Beta implementation

GitVersionConfig.yaml

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

README.md

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Polly is a member of the [.NET Foundation](https://www.dotnetfoundation.org/abou
1010

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

13-
# Installing via NuGet
13+
# Installing Polly.Caching.MemoryCache via NuGet
1414

1515
Install-Package Polly.Caching.MemoryCache
1616

@@ -24,16 +24,66 @@ Polly.Caching.MemoryCache supports .NET4.0, .NET4.5 and .NetStandard 1.3.
2424

2525
## Dependencies
2626

27-
[To come]
27+
Polly.Caching.MemoryCache works with Polly v5.4.0 and above.
2828

2929
# How to use the Polly.Caching.MemoryCache plugin
3030

31-
[To come]
31+
```csharp
32+
// (1a): Create a MemoryCacheProvider instance in the .NET Framework, using the Polly.Caching.MemoryCache nuget package.
33+
// (full namespaces and types only shown here for disambiguation)
34+
Polly.Caching.MemoryCache.MemoryCacheProvider memoryCacheProvider
35+
= new Polly.Caching.MemoryCache.MemoryCacheProvider(System.Runtime.Caching.MemoryCache.Default);
3236

37+
// Or (1b): Create a MemoryCacheProvider instance in .NET Core / .NET Standard.
38+
// (full namespaces and types only shown here for disambiguation)
39+
// NB Only if you want to create your own Microsoft.Extensions.Caching.Memory.MemoryCache instance:
40+
Microsoft.Extensions.Caching.Memory.IMemoryCache memoryCache
41+
= new Microsoft.Extensions.Caching.Memory.MemoryCache(new Microsoft.Extensions.Caching.Memory.MemoryCacheOptions());
42+
Polly.Caching.MemoryCache.MemoryCacheProvider memoryCacheProvider
43+
= new Polly.Caching.MemoryCache.MemoryCacheProvider(memoryCache);
3344

34-
## How to use the Polly Cache policy
45+
// (2) Create a Polly cache policy using that Polly.Caching.MemoryCache.MemoryCacheProvider instance.
46+
var cachePolicy = Policy.Cache(memoryCacheProvider, TimeSpan.FromMinutes(5));
3547

36-
See the [To be expanded] [Polly readme](https://github.com/App-vNext/Polly/wiki/Cache) or [To be expanded] [deep doco on the Polly wiki](https://github.com/App-vNext/Polly/wiki/Cache).
48+
49+
50+
// Or (1c): Configure by dependency injection within ASP.NET Core
51+
// See https://docs.microsoft.com/en-us/aspnet/core/performance/caching/memory
52+
// and https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection#registering-your-own-services
53+
54+
// (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.)
55+
56+
// For example:
57+
public class Startup
58+
{
59+
public void ConfigureServices(IServiceCollection services)
60+
{
61+
services.AddMemoryCache();
62+
services.AddSingleton<Polly.Registry.IPolicyRegistry<string>, Polly.Registry.PolicyRegistry>();
63+
// ...
64+
}
65+
66+
public void Configure(..., IPolicyRegistry<string> policyRegistry, IMemoryCache memoryCache)
67+
{
68+
Polly.Caching.MemoryCache.MemoryCacheProvider memoryCacheProvider
69+
= new Polly.Caching.MemoryCache.MemoryCacheProvider(memoryCache);
70+
var cachePolicy = Policy.Cache(memoryCacheProvider, TimeSpan.FromMinutes(5));
71+
policyRegistry.Add("myCachePolicy", cachePolicy);
72+
// ...
73+
}
74+
}
75+
76+
// In a controller, inject the policyRegistry and retrieve the policy:
77+
// (magic string "myCachePolicy" only hard-coded here to keep the example simple!)
78+
public MyController(IPolicyRegistry<string> policyRegistry)
79+
{
80+
_cachePolicy = policyRegistry["myCachePolicy"];
81+
// ...
82+
}
83+
84+
```
85+
86+
For many more configuration options and usage examples of the main Polly `CachePolicy`, see the [main Polly readme](https://github.com/App-vNext/Polly/wiki/Cache) and [deep doco on the Polly wiki](https://github.com/App-vNext/Polly/wiki/Cache).
3787

3888

3989
# Release notes
@@ -43,6 +93,7 @@ For details of changes by release see the [change log](CHANGELOG.md).
4393

4494
# Acknowledgements
4595

96+
* [@reisenberger](https://github.com/reisenberger) - MemoryCache implementation
4697
* [@seanfarrow](https://github.com/seanfarrow) and [@reisenberger](https://github.com/reisenberger) - Initial caching architecture in the main Polly repo
4798
* [@kesmy](https://github.com/kesmy) - original structuring of the build for msbuild15, in the main Polly repo
4899

build.cake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Task("__UpdateDotNetStandardAssemblyVersionNumber")
135135
// This build Task can be removed when GitVersionTask supports .Net Standard assemblies.
136136
var assemblySemVer = gitVersionOutput["AssemblySemVer"].ToString();
137137
Information("Updating NetStandard1.3 AssemblyVersion to {0}", assemblySemVer);
138-
var replacedFiles = ReplaceRegexInFiles("./src/Polly.NetStandard13/Properties/AssemblyInfo.cs", "AssemblyVersion[(]\".*\"[)]", "AssemblyVersion(\"" + assemblySemVer +"\")");
138+
var replacedFiles = ReplaceRegexInFiles("./src/Polly.Caching.MemoryCache.NetStandard13/Properties/AssemblyInfo.cs", "AssemblyVersion[(]\".*\"[)]", "AssemblyVersion(\"" + assemblySemVer +"\")");
139139
if (!replacedFiles.Any())
140140
{
141141
Information("NetStandard1.3 AssemblyVersion could not be updated.");

src/Polly.Caching.MemoryCache.NetStandard13/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Runtime.CompilerServices;
44

55
[assembly: AssemblyTitle("Polly.Caching.MemoryCache")]
6-
[assembly: AssemblyVersion("0.2.0.0")]
6+
[assembly: AssemblyVersion("1.0.0.0")]
77
[assembly: CLSCompliant(false)] // Because Microsoft.Extensions.Caching.Memory.MemoryCache, on which Polly.Caching.MemoryCache.NetStandard13 depends, is not CLSCompliant.
88

99
[assembly: InternalsVisibleTo("Polly.Caching.MemoryCache.NetStandard13.Specs")]

src/Polly.Caching.MemoryCache.nuspec

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
<tags>Exception Handling Resilience Transient Fault Policy Cache Aside Cache-aside</tags>
1414
<copyright>Copyright © 2017, App vNext</copyright>
1515
<releaseNotes>
16+
## 1.0-RC
17+
18+
- Upgrade to Polly v5.4.0
19+
- Correctly state RC dependency (Polly v5.4.0)
20+
1621
## 0.2-alpha
1722

1823
- Upgrade to msbuild15 build process
@@ -24,18 +29,18 @@
2429
</releaseNotes>
2530
<dependencies>
2631
<group targetFramework="net45">
27-
<dependency id="Polly" version="5.3.1" />
32+
<dependency id="Polly" version="5.4.0" />
2833
</group>
2934
<group targetFramework="netstandard1.3">
3035
<dependency id="NETStandard.Library" version="1.6.1" />
31-
<dependency id="Polly" version="5.3.1" />
36+
<dependency id="Polly" version="5.4.0" />
3237
</group>
3338
<group targetFramework="net40">
3439
<dependency id="Microsoft.Bcl.Async" version="1.0.168" />
3540
<dependency id="Microsoft.Bcl" version="1.1.10" />
3641
<dependency id="Microsoft.Bcl.Build" version="1.0.21" />
3742
<dependency id="Nito.AsyncEx" version="3.0.1" />
38-
<dependency id="Polly.Net40Async" version="5.3.1" />
43+
<dependency id="Polly.Net40Async" version="5.4.0" />
3944
</group>
4045
</dependencies>
4146
</metadata>

0 commit comments

Comments
 (0)