Skip to content

Commit 32c6228

Browse files
authored
Merge pull request #394 from App-vNext/v570dev
Merge v5.7.0dev branch to master
2 parents 64095be + 4df2018 commit 32c6228

37 files changed

Lines changed: 2000 additions & 125 deletions

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2+
## 5.7.0
3+
- Minor cache fixes
4+
- Add ability to calculate cache Ttl based on item to cache
5+
- Allow user-created custom policies
6+
17
## 5.6.1
28
- Extend PolicyWrap syntax with interfaces
39

GitVersionConfig.yaml

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

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,7 @@ For details of changes by release see the [change log](https://github.com/App-vN
951951
* [@reisenberger](https://github.com/reisenberger) - Add new .HandleInner<TException>(...) syntax for handling inner exceptions natively.
952952
* [@rjongeneelen](https://github.com/rjongeneelen) and [@reisenberger](https://github.com/reisenberger) - Allow PolicyWrap configuration to configure policies via interfaces.
953953
* [@reisenberger](https://github.com/reisenberger) - Performance improvements.
954+
* [@awarrenlove](https://github.com/awarrenlove) - Add ability to calculate cache Ttl based on item to cache.
954955
955956
# Sample Projects
956957

build.cake

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
///////////////////////////////////////////////////////////////////////////////
1+
///////////////////////////////////////////////////////////////////////////////
22
// ARGUMENTS
33
///////////////////////////////////////////////////////////////////////////////
44

@@ -92,12 +92,16 @@ Teardown(_ =>
9292
Task("__Clean")
9393
.Does(() =>
9494
{
95-
CleanDirectories(new DirectoryPath[] {
95+
DirectoryPath[] cleanDirectories = new DirectoryPath[] {
9696
buildDir,
97-
artifactsDir,
9897
testResultsDir,
99-
nupkgDestDir
100-
});
98+
nupkgDestDir,
99+
artifactsDir
100+
};
101+
102+
CleanDirectories(cleanDirectories);
103+
104+
foreach(var path in cleanDirectories) { EnsureDirectoryExists(path); }
101105

102106
foreach(var path in solutionPaths)
103107
{

src/Polly.Net40Async.nuspec

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
<releaseNotes>
1616
v5.0 is a major release with significant new resilience policies: Timeout; Bulkhead Isolation; Fallback; Cache; and PolicyWrap. See release notes back to v5.0.0 for full details.
1717

18+
5.7.0
19+
---------------------
20+
- Minor cache fixes
21+
- Add ability to calculate cache Ttl based on item to cache
22+
- Allow user-created custom policies
23+
1824
5.6.1
1925
---------------------
2026
- Extend PolicyWrap syntax with interfaces

src/Polly.NetStandard11/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")]
6-
[assembly: AssemblyVersion("5.6.1.0")]
6+
[assembly: AssemblyVersion("5.7.0.0")]
77
[assembly: CLSCompliant(true)]
88

99
[assembly: InternalsVisibleTo("Polly.NetStandard11.Specs")]

src/Polly.Shared/Caching/CacheEngine.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ internal static partial class CacheEngine
77
{
88
internal static TResult Implementation<TResult>(
99
ISyncCacheProvider<TResult> cacheProvider,
10-
ITtlStrategy ttlStrategy,
10+
ITtlStrategy<TResult> ttlStrategy,
1111
Func<Context, string> cacheKeyStrategy,
1212
Func<Context, CancellationToken, TResult> action,
1313
Context context,
@@ -48,8 +48,8 @@ internal static TResult Implementation<TResult>(
4848

4949
TResult result = action(context, cancellationToken);
5050

51-
Ttl ttl = ttlStrategy.GetTtl(context);
52-
if (ttl.Timespan > TimeSpan.Zero)
51+
Ttl ttl = ttlStrategy.GetTtl(context, result);
52+
if (ttl.Timespan > TimeSpan.Zero && result != null && !result.Equals(default(TResult)))
5353
{
5454
try
5555
{

src/Polly.Shared/Caching/CacheEngineAsync.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ internal static partial class CacheEngine
88
{
99
internal static async Task<TResult> ImplementationAsync<TResult>(
1010
IAsyncCacheProvider<TResult> cacheProvider,
11-
ITtlStrategy ttlStrategy,
11+
ITtlStrategy<TResult> ttlStrategy,
1212
Func<Context, string> cacheKeyStrategy,
1313
Func<Context, CancellationToken, Task<TResult>> action,
1414
Context context,
@@ -50,8 +50,8 @@ internal static async Task<TResult> ImplementationAsync<TResult>(
5050

5151
TResult result = await action(context, cancellationToken).ConfigureAwait(continueOnCapturedContext);
5252

53-
Ttl ttl = ttlStrategy.GetTtl(context);
54-
if (ttl.Timespan > TimeSpan.Zero)
53+
Ttl ttl = ttlStrategy.GetTtl(context, result);
54+
if (ttl.Timespan > TimeSpan.Zero && result != null && !result.Equals(default(TResult)))
5555
{
5656
try
5757
{

src/Polly.Shared/Caching/CachePolicy.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public override TResult ExecuteInternal<TResult>(Func<Context, CancellationToken
5555
{
5656
return CacheEngine.Implementation<TResult>(
5757
_syncCacheProvider.For<TResult>(),
58-
_ttlStrategy,
58+
_ttlStrategy.For<TResult>(),
5959
_cacheKeyStrategy,
6060
action,
6161
context,
@@ -75,7 +75,7 @@ public partial class CachePolicy<TResult> : Policy<TResult>, ICachePolicy<TResul
7575
{
7676
internal CachePolicy(
7777
ISyncCacheProvider<TResult> syncCacheProvider,
78-
ITtlStrategy ttlStrategy,
78+
ITtlStrategy<TResult> ttlStrategy,
7979
Func<Context, string> cacheKeyStrategy,
8080
Action<Context, string> onCacheGet,
8181
Action<Context, string> onCacheMiss,

src/Polly.Shared/Caching/CachePolicyAsync.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public override Task<TResult> ExecuteAsyncInternal<TResult>(Func<Context, Cancel
4747
{
4848
return CacheEngine.ImplementationAsync<TResult>(
4949
_asyncCacheProvider.AsyncFor<TResult>(),
50-
_ttlStrategy,
50+
_ttlStrategy.For<TResult>(),
5151
_cacheKeyStrategy,
5252
action,
5353
context,
@@ -65,7 +65,7 @@ public partial class CachePolicy<TResult>
6565
{
6666
internal CachePolicy(
6767
IAsyncCacheProvider<TResult> asyncCacheProvider,
68-
ITtlStrategy ttlStrategy,
68+
ITtlStrategy<TResult> ttlStrategy,
6969
Func<Context, string> cacheKeyStrategy,
7070
Action<Context, string> onCacheGet,
7171
Action<Context, string> onCacheMiss,

0 commit comments

Comments
 (0)