Skip to content

Commit e26539c

Browse files
authored
Merge pull request #13 from reisenberger/v300
Version 3.0.0: For compatibility with (forthcoming) Polly v7.0.0
2 parents b7919d9 + 8618346 commit e26539c

28 files changed

+577
-121
lines changed

CHANGELOG.md

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

3+
## 3.0.0
4+
- Allow caching of `default(TResult)`
5+
- Compatible with Polly >= v7
6+
37
## 2.0.1
48
- No functional changes
59
- Indicate compatibility with Polly < v7

GitVersionConfig.yaml

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

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,19 @@ Polly.Caching.Distributed supports .NET Standard 1.1 and .NET Standard 2.0.
2828

2929
## Versions and Dependencies
3030

31+
Polly.Caching.Distributed >=v3.0 requires:
32+
33+
+ [Polly](https://nuget.org/packages/polly) >= v7.0.0.
34+
+ [Microsoft.Extensions.Caching.Abstractions](https://www.nuget.org/packages/Microsoft.Extensions.Caching.Abstractions/) v2.0.2 or above.
35+
3136
Polly.Caching.Distributed >=v2.0 and <v3 requires:
3237

33-
+ [Polly](nuget.org/packages/polly) >= v6.0.1 and <v7.
38+
+ [Polly](https://nuget.org/packages/polly) >= v6.0.1 and <v7.
3439
+ [Microsoft.Extensions.Caching.Abstractions](https://www.nuget.org/packages/Microsoft.Extensions.Caching.Abstractions/) v2.0.2 or above.
3540

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

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

4146

@@ -129,6 +134,7 @@ For details of changes by release see the [change log](CHANGELOG.md).
129134
* [@seanfarrow](https://github.com/seanfarrow) and [@reisenberger](https://github.com/reisenberger) - Initial caching architecture in the main Polly repo
130135
* [@reisenberger](https://github.com/reisenberger) - `IDistributedCache` implementation
131136
* [@seanfarrow](https://github.com/seanfarrow) - v2.0 update to Signed packages only to correspond with Polly v6.0.1
137+
* [@reisenberger](https://github.com/reisenberger) - Update to Polly v7.0.0
132138

133139
# Instructions for Contributing
134140

src/Polly.Caching.Distributed.NetStandard11.Specs/Polly.Caching.Distributed.NetStandard11.Specs.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PropertyGroup>
88
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
99
<DebugType>full</DebugType>
10-
<DefineConstants>TRACE;DEBUG;NETCOREAPP1_1;NETCOREAPP1_1;PORTABLE</DefineConstants>
10+
<DefineConstants>TRACE;DEBUG;NETCOREAPP1_1;PORTABLE</DefineConstants>
1111
</PropertyGroup>
1212
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
1313
<DebugType>pdbonly</DebugType>
@@ -18,9 +18,10 @@
1818
<PackageReference Include="FluentAssertions" Version="4.19.3" />
1919
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
2020
<PackageReference Include="Moq" Version="4.7.145" />
21+
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
2122
<PackageReference Include="xunit" Version="2.2.0" />
2223
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
23-
<PackageReference Include="Polly" Version="6.0.1" />
24+
<PackageReference Include="Polly" Version="7.0.0" />
2425

2526
</ItemGroup>
2627
<ItemGroup>

src/Polly.Caching.Distributed.NetStandard11/Polly.Caching.Distributed.NetStandard11.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
</ItemGroup>
3232
<ItemGroup>
3333
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="1.1.2" />
34-
<PackageReference Include="Polly" Version="6.0.1" />
34+
<PackageReference Include="Polly" Version="7.0.0" />
35+
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
3536
</ItemGroup>
3637
<Import Project="..\Polly.Caching.Distributed.Shared\Polly.Caching.Distributed.Shared.projitems" Label="Shared" />
3738
</Project>

src/Polly.Caching.Distributed.NetStandard11/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
using System.Runtime.CompilerServices;
44

55
[assembly: AssemblyTitle("Polly.Caching.Distributed")]
6-
[assembly: AssemblyVersion("2.0.0.0")]
7-
[assembly: AssemblyFileVersion("2.0.1.0")]
8-
[assembly: AssemblyInformationalVersion("2.0.1.0")]
6+
[assembly: AssemblyVersion("3.0.0.0")]
7+
[assembly: AssemblyFileVersion("3.0.0.0")]
8+
[assembly: AssemblyInformationalVersion("3.0.0.0")]
99
[assembly: CLSCompliant(false)] // Because Microsoft.Extensions.Caching.Memory.IDistributedCache, on which Polly.Caching.IDistributedCache.NetStandard11 depends, is not CLSCompliant.
1010

1111
[assembly: InternalsVisibleTo("Polly.Caching.Distributed.NetStandard11.Specs")]

src/Polly.Caching.Distributed.NetStandard20.Specs/Polly.Caching.Distributed.NetStandard20.Specs.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PropertyGroup>
88
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
99
<DebugType>full</DebugType>
10-
<DefineConstants>TRACE;DEBUG;NETCOREAPP1_1;NETCOREAPP1_1;PORTABLE</DefineConstants>
10+
<DefineConstants>TRACE;DEBUG;NETCOREAPP2_0;PORTABLE</DefineConstants>
1111
</PropertyGroup>
1212
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
1313
<DebugType>pdbonly</DebugType>
@@ -16,11 +16,13 @@
1616
</PropertyGroup>
1717
<ItemGroup>
1818
<PackageReference Include="FluentAssertions" Version="4.19.3" />
19+
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="2.0.2" />
1920
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
2021
<PackageReference Include="Moq" Version="4.7.145" />
22+
<PackageReference Include="Polly.Caching.Serialization.Json" Version="3.0.0" />
2123
<PackageReference Include="xunit" Version="2.2.0" />
2224
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
23-
<PackageReference Include="Polly" Version="6.0.1" />
25+
<PackageReference Include="Polly" Version="7.0.0" />
2426

2527
</ItemGroup>
2628
<ItemGroup>

src/Polly.Caching.Distributed.NetStandard20/Polly.Caching.Distributed.NetStandard20.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
</ItemGroup>
3232
<ItemGroup>
3333
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="2.0.2" />
34-
<PackageReference Include="Polly" Version="6.0.1" />
34+
<PackageReference Include="Polly" Version="7.0.0" />
3535
</ItemGroup>
3636
<Import Project="..\Polly.Caching.Distributed.Shared\Polly.Caching.Distributed.Shared.projitems" Label="Shared" />
3737
</Project>

src/Polly.Caching.Distributed.NetStandard20/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
using System.Runtime.CompilerServices;
44

55
[assembly: AssemblyTitle("Polly.Caching.Distributed")]
6-
[assembly: AssemblyVersion("2.0.0.0")]
7-
[assembly: AssemblyFileVersion("2.0.1.0")]
8-
[assembly: AssemblyInformationalVersion("2.0.1.0")]
6+
[assembly: AssemblyVersion("3.0.0.0")]
7+
[assembly: AssemblyFileVersion("3.0.0.0")]
8+
[assembly: AssemblyInformationalVersion("3.0.0.0")]
99
[assembly: CLSCompliant(false)] // Because Microsoft.Extensions.Caching.Memory.IDistributedCache, on which Polly.Caching.IDistributedCache.NetStandard11 depends, is not CLSCompliant.
1010

1111
[assembly: InternalsVisibleTo("Polly.Caching.Distributed.NetStandard20.Specs")]

src/Polly.Caching.Distributed.Shared/NetStandardIDistributedCacheByteArrayProvider.cs

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ namespace Polly.Caching.Distributed
99
/// </summary>
1010
public class NetStandardIDistributedCacheByteArrayProvider : NetStandardIDistributedCacheProvider<byte[]>
1111
{
12-
private readonly byte[] Empty = new byte[0];
13-
1412
/// <summary>
1513
/// Initializes a new instance of the <see cref="NetStandardIDistributedCacheByteArrayProvider"/> class.
1614
/// </summary>
@@ -23,13 +21,16 @@ public NetStandardIDistributedCacheByteArrayProvider(Microsoft.Extensions.Cachin
2321
/// Gets a value from cache.
2422
/// </summary>
2523
/// <param name="key">The cache key.</param>
26-
/// <returns>The value from cache; or null, if none was found.</returns>
27-
public override byte[] Get(String key)
24+
/// <returns>
25+
/// A tuple whose first element is a bool indicating whether the key was found in the cache,
26+
/// and whose second element is the value from the cache.
27+
/// </returns>
28+
public override (bool, byte[]) TryGet(string key)
2829
{
29-
byte[] returned = _cache.Get(key);
30-
return returned == null || returned.Length == 0 ? null : returned; // Because Polly CachePolicy expects providers to return "no value held" as null.
30+
byte[] fromCache = _cache.Get(key);
31+
return (fromCache != null, fromCache);
3132
}
32-
33+
3334
/// <summary>
3435
/// Puts the specified value in the cache.
3536
/// </summary>
@@ -38,26 +39,33 @@ public override byte[] Get(String key)
3839
/// <param name="ttl">The time-to-live for the cache entry.</param>
3940
public override void Put(string key, byte[] value, Ttl ttl)
4041
{
41-
_cache.Set(key, value ?? Empty, ttl.ToDistributedCacheEntryOptions());
42+
_cache.Set(key, value, ttl.ToDistributedCacheEntryOptions());
4243
}
4344

4445
/// <summary>
45-
/// Gets a value from the memory cache as part of an asynchronous execution. <para><remarks>The implementation is synchronous as there is no advantage to an asynchronous implementation for an in-memory cache.</remarks></para>
46+
/// Gets a value from the memory cache as part of an asynchronous execution.
4647
/// </summary>
4748
/// <param name="key">The cache key.</param>
4849
/// <param name="cancellationToken">The cancellation token. </param>
49-
/// <param name="continueOnCapturedContext">Whether async calls should continue on a captured synchronization context. <para><remarks>For <see cref="NetStandardIDistributedCacheByteArrayProvider"/>, this parameter is irrelevant and is ignored, as the Microsoft.Extensions.Caching.Distributed.IDistributedCache interface does not support it.</remarks></para></param>
50-
/// <returns>A <see cref="Task{TResult}" /> promising as Result the value from cache; or null, if none was found.</returns>
51-
public override async Task<byte[]> GetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext)
50+
/// <param name="continueOnCapturedContext">Whether async calls should continue on a captured synchronization context. <para><remarks>For <see cref="NetStandardIDistributedCacheProvider{TCache}"/>, this parameter is irrelevant and is ignored, as the Microsoft.Extensions.Caching.Distributed.IDistributedCache interface does not support it.</remarks></para></param>
51+
/// <returns>
52+
/// A <see cref="Task{TResult}" /> promising as Result a tuple whose first element is a value indicating whether
53+
/// the key was found in the cache, and whose second element is the value from the cache.
54+
/// </returns>
55+
public override async Task<(bool, byte[])> TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext)
5256
{
5357
cancellationToken.ThrowIfCancellationRequested();
54-
byte[] returned = await _cache.GetAsync(key);
55-
return returned == null || returned.Length == 0 ? null : returned; // Because Polly CachePolicy expects providers to return "no value held" as null.
58+
59+
byte[] fromCache = await _cache.GetAsync(key
60+
#if NETSTANDARD2_0
61+
, cancellationToken
62+
#endif
63+
);
64+
return (fromCache != null, fromCache);
5665
}
5766

5867
/// <summary>
5968
/// Puts the specified value in the cache as part of an asynchronous execution.
60-
/// <para><remarks>The implementation is synchronous as there is no advantage to an asynchronous implementation for an in-memory cache.</remarks></para>
6169
/// </summary>
6270
/// <param name="key">The cache key.</param>
6371
/// <param name="value">The value to put into the cache.</param>
@@ -69,7 +77,11 @@ public override Task PutAsync(string key, byte[] value, Ttl ttl, CancellationTok
6977
{
7078
cancellationToken.ThrowIfCancellationRequested();
7179

72-
return _cache.SetAsync(key, value ?? Empty, ttl.ToDistributedCacheEntryOptions());
80+
return _cache.SetAsync(key, value, ttl.ToDistributedCacheEntryOptions()
81+
#if NETSTANDARD2_0
82+
, cancellationToken
83+
#endif
84+
);
7385
}
7486

7587

0 commit comments

Comments
 (0)