Skip to content

Commit d23e2d6

Browse files
silentbobbertIan RobertsonsergevmVan Meerbeeck, SergeIan Robertson
authored
Develop (#45)
* Efcache 1.3.2 upgrade with netstandard2.1 (#44) * Added netstandard2.0 target framework. * Upgrade to EFCache v1.3.2, because of broken binary formatter serialization on System.RuntimeType (see moozzyk/EFCache#51) since dotnet core 2. Added target framework netstandard2.1. Co-authored-by: Van Meerbeeck, Serge <Serge.VanMeerbeeck@wolterskluwer.com> * Prepare PR for release Co-authored-by: Ian Robertson <ian.danger.robertson@gmail.com> Co-authored-by: sergevm <serge.vanmeerbeeck@gmail.com> Co-authored-by: Van Meerbeeck, Serge <Serge.VanMeerbeeck@wolterskluwer.com> Co-authored-by: Ian Robertson <ian.robertson@willistowerswatson.com>
1 parent efae42e commit d23e2d6

11 files changed

Lines changed: 66 additions & 68 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*.user
77
*.sln.docstates
88
.vs
9+
.idea
910

1011
# Build results
1112

EFCache.Redis.Tests/EFCache.Redis.Tests.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net48</TargetFramework>
4+
<TargetFrameworks>net48;netcoreapp3.0</TargetFrameworks>
55
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
66

77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Moq" Version="4.14.5" />
10+
<PackageReference Include="Moq" Version="4.14.7" />
1111
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
1212
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
13-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
1414
</ItemGroup>
1515

1616
<ItemGroup>

EFCache.Redis.Tests/RedisCacheTests.cs

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public RedisCacheTests()
2828
try
2929
{
3030
// See if we have a running copy of redis in a K8s Cluster
31-
// helm install --name redis-dev --set password=secretpassword --set master.disableCommands= stable/redis
31+
// helm upgrade --install redis-dev --set password=secretpassword --set master.disableCommands= bitnami/redis
32+
3233
// kubectl get secret --namespace default redis-dev -o jsonpath="{.data.redis-password}" | base64 --decode
3334
// kubectl port-forward --namespace default svc/redis-dev-master 6379:6379
3435
var connString = "localhost:6379,password=secretpassword";
@@ -38,12 +39,12 @@ public RedisCacheTests()
3839
AdminConnectionString = string.Join(",", connString, "allowAdmin=true");
3940

4041
}
41-
catch (Exception)
42+
catch(Exception)
4243
{
4344
// Could not connect to redis above, so start a local copy
4445
RedisStorageEmulatorManager.Instance.StartProcess(false);
4546
}
46-
47+
4748
}
4849

4950
[TestMethod]
@@ -98,7 +99,7 @@ public void Item_still_returned_after_sliding_expiration_period()
9899

99100
object fromCache = null;
100101
// In a loop of 20 seconds retrieve the item every 5 second seconds.
101-
for (var i = 0; i < 4; i++)
102+
for(var i = 0; i < 4; i++)
102103
{
103104
Thread.Sleep(5000); // Wait 5 seconds
104105
// Retrieve item again. This should update LastAccess and as such keep the item 'alive'
@@ -155,7 +156,7 @@ public void Count_returns_numers_of_cached_entries()
155156
Assert.AreEqual(0, cache.Count);
156157
}
157158

158-
159+
159160
[TestMethod]
160161
public async Task ThreadingBlockTest()
161162
{
@@ -167,8 +168,10 @@ public async Task ThreadingBlockTest()
167168

168169
cache.CachingFailed += (sender, e) =>
169170
{
170-
if (e?.InnerException is LockTimeoutException)
171+
if(e?.InnerException is LockTimeoutException)
172+
{
171173
exception = e.InnerException;
174+
}
172175
};
173176
cache.Purge();
174177

@@ -185,20 +188,21 @@ public async Task ThreadingBlockTest()
185188

186189
var tasks = new Task[10];
187190

188-
for (var i = 0; i < 10; i++)
191+
for(var i = 0; i < 10; i++)
189192
{
190193
var icopy = i;
191194
tasks[i] = Task.Run(() =>
192195
{
193196
var watch = new Stopwatch();
194197
watch.Start();
195198
Debug.WriteLine($"Invalidate {icopy} start");
196-
if (i == 9)
199+
if(i == 9)
200+
{
197201
cache.InvalidateItem("1");
202+
}
198203
else
199204
{
200-
object val;
201-
cache.GetItem("1", out val);
205+
cache.GetItem("1", out var val);
202206
}
203207
watch.Stop();
204208
Debug.WriteLine($"Invalidate {icopy} complete after {watch.ElapsedMilliseconds}");
@@ -211,8 +215,7 @@ public async Task ThreadingBlockTest()
211215
Debug.WriteLine($"Get start");
212216
var watch = new Stopwatch();
213217
watch.Start();
214-
object value;
215-
cache.GetItem("1", out value);
218+
cache.GetItem("1", out var value);
216219
watch.Stop();
217220
Debug.WriteLine($"Get complete after {watch.ElapsedMilliseconds}");
218221
});
@@ -227,10 +230,7 @@ public async Task ThreadingBlockTest()
227230

228231
}
229232

230-
private void Cache_CachingFailed(object sender, RedisCacheException e)
231-
{
232-
throw new NotImplementedException();
233-
}
233+
private void Cache_CachingFailed(object sender, RedisCacheException e) => throw new NotImplementedException();
234234

235235

236236
[TestMethod]
@@ -244,7 +244,7 @@ public void Count_does_not_return_expired_entries()
244244

245245
cache.PutItem("1", new object(), new string[0], TimeSpan.MaxValue, DateTimeOffset.Now.AddSeconds(1));
246246

247-
Assert.AreEqual(1, cache.Count);
247+
Assert.AreEqual(1, cache.Count);
248248

249249
Thread.Sleep(1000);
250250

@@ -282,31 +282,19 @@ public void GetItem_validates_parameters()
282282

283283
[TestMethod]
284284
[ExpectedException(typeof(ArgumentOutOfRangeException))]
285-
public void PutItem_validates_key_parameter()
286-
{
287-
new RedisCache(RegularConnectionString).PutItem(null, 42, new string[0], TimeSpan.Zero, DateTimeOffset.Now);
288-
}
285+
public void PutItem_validates_key_parameter() => new RedisCache(RegularConnectionString).PutItem(null, 42, new string[0], TimeSpan.Zero, DateTimeOffset.Now);
289286

290287
[TestMethod]
291288
[ExpectedException(typeof(ArgumentNullException))]
292-
public void PutItem_validates_dependentEntitySets_parameter()
293-
{
294-
new RedisCache(RegularConnectionString).PutItem("1", 42, null, TimeSpan.Zero, DateTimeOffset.Now);
295-
}
289+
public void PutItem_validates_dependentEntitySets_parameter() => new RedisCache(RegularConnectionString).PutItem("1", 42, null, TimeSpan.Zero, DateTimeOffset.Now);
296290

297291
[TestMethod]
298292
[ExpectedException(typeof(ArgumentNullException))]
299-
public void InvalidateSets_validates_parameters()
300-
{
301-
new RedisCache(RegularConnectionString).InvalidateSets(null);
302-
}
293+
public void InvalidateSets_validates_parameters() => new RedisCache(RegularConnectionString).InvalidateSets(null);
303294

304295
[TestMethod]
305296
[ExpectedException(typeof(ArgumentOutOfRangeException))]
306-
public void InvalidateItem_validates_parameters()
307-
{
308-
new RedisCache(RegularConnectionString).InvalidateItem(null);
309-
}
297+
public void InvalidateItem_validates_parameters() => new RedisCache(RegularConnectionString).InvalidateItem(null);
310298

311299
[TestMethod]
312300
public void GetItem_does_not_crash_if_cache_is_unavailable()

EFCache.Redis.Tests/StorageEmulatorManager.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@ protected StorageEmulatorManager(string processName, ProcessStartInfo processSta
2424

2525
public void StartProcess(bool waitForExit)
2626
{
27-
if (IsProcessStarted()) return;
27+
if(IsProcessStarted())
28+
{
29+
return;
30+
}
2831

29-
using (var process = Process.Start(_processStartInfo))
32+
using(var process = Process.Start(_processStartInfo))
3033
{
31-
if (process != null && waitForExit) process.WaitForExit();
34+
if(process != null && waitForExit)
35+
{
36+
process.WaitForExit();
37+
}
3238
}
3339
}
3440

EFCache.Redis/EFCache.Redis.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net48</TargetFramework>
4+
<TargetFrameworks>net461;net472;net48;netstandard2.1</TargetFrameworks>
55
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="EntityFramework.Cache" Version="1.3.1" />
9+
<PackageReference Include="EntityFramework.Cache" Version="1.3.2" />
1010
<PackageReference Include="StackExchange.Redis" Version="2.1.58" />
1111
</ItemGroup>
1212

EFCache.Redis/EFCache.Redis.nuspec

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
33
<metadata>
44
<id>EFCache.Redis</id>
5-
<version>2020.8.21.1</version>
5+
<version>2020.8.21.2</version>
66
<authors>Ian Robertson</authors>
77
<projectUrl>https://github.com/silentbobbert/EFCache.Redis</projectUrl>
88
<iconUrl>https://avatars0.githubusercontent.com/u/3257988</iconUrl>
@@ -12,7 +12,7 @@
1212
<tags>EF6 EF6.3 Redis Caching L2</tags>
1313
<dependencies>
1414
<dependency id="EntityFramework" version="6.3.0" />
15-
<dependency id="EntityFramework.Cache" version="1.3.1" />
15+
<dependency id="EntityFramework.Cache" version="1.3.2" />
1616
<dependency id="StackExchange.Redis" version="2.1.58" />
1717
<dependency id="Pipelines.Sockets.Unofficial" version="2.1.16" />
1818
<dependency id="System.Buffers" version="4.5.1" />
@@ -33,5 +33,7 @@
3333
<file src="bin\Release\net472\EFCache.Redis.pdb" target="lib\net472\EFCache.Redis.pdb" />
3434
<file src="bin\Release\net48\EFCache.Redis.dll" target="lib\net48\EFCache.Redis.dll" />
3535
<file src="bin\Release\net48\EFCache.Redis.pdb" target="lib\net48\EFCache.Redis.pdb" />
36+
<file src="bin\Release\netstandard2.1\EFCache.Redis.dll" target="lib\netstandard2.1\EFCache.Redis.dll" />
37+
<file src="bin\Release\netstandard2.1\EFCache.Redis.pdb" target="lib\netstandard2.1\EFCache.Redis.pdb" />
3638
</files>
3739
</package>

EFCache.Redis/IRedisCache.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using EFCache;
2-
using System;
1+
using System;
32

43
namespace EFCache.Redis
54
{

EFCache.Redis/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@
3131
// Build Number
3232
// Revision
3333
//
34-
[assembly: AssemblyVersion("2020.8.21.1")]
35-
[assembly: AssemblyFileVersion("2020.8.21.1")]
34+
[assembly: AssemblyVersion("2020.11.9.1")]
35+
[assembly: AssemblyFileVersion("2020.11.9.1")]
3636

EFCache.Redis/RedisCache.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ public bool GetItem(string key, out object value)
9191
OnCachingFailed(e);
9292
}
9393

94-
if (value == null) return false;
94+
if (value == null)
95+
{
96+
return false;
97+
}
9598

9699
var entry = (CacheEntry)value;
97100

@@ -187,7 +190,11 @@ private TimeSpan GetTimeSpanExpiration(DateTimeOffset expiration)
187190
private static string HashKey(string key)
188191
{
189192
//Looking up large Keys in Redis can be expensive (comparing Large Strings), so if keys are large, hash them, otherwise if keys are short just use as-is
190-
if (key.Length <= 128) return key;
193+
if (key.Length <= 128)
194+
{
195+
return key;
196+
}
197+
191198
using (var sha = new SHA1CryptoServiceProvider())
192199
{
193200
key = Convert.ToBase64String(sha.ComputeHash(Encoding.UTF8.GetBytes(key)));
@@ -244,7 +251,10 @@ public void InvalidateItem(string key)
244251
{
245252
var entry = _database.Get<CacheEntry>(key);
246253

247-
if (entry == null) return;
254+
if (entry == null)
255+
{
256+
return;
257+
}
248258

249259
_database.KeyDelete(key, CommandFlags.FireAndForget);
250260

EFCache.Redis/StackExchangeRedisExtensions.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ public static void Set<T>(this IDatabase cache, string key, T value, TimeSpan ex
2121

2222
static byte[] Serialize<T>(T o) where T : class
2323
{
24-
if (o == null) return null;
24+
if (o == null)
25+
{
26+
return null;
27+
}
28+
2529
var binaryFormatter = new BinaryFormatter();
2630

2731
using (var memoryStream = new MemoryStream())
@@ -34,7 +38,11 @@ static byte[] Serialize<T>(T o) where T : class
3438

3539
static T Deserialize<T>(byte[] stream)
3640
{
37-
if (stream == null || !stream.Any()) return default(T);
41+
if (stream == null || !stream.Any())
42+
{
43+
return default(T);
44+
}
45+
3846
var binaryFormatter = new BinaryFormatter();
3947
using (var memoryStream = new MemoryStream(stream))
4048
{

0 commit comments

Comments
 (0)