diff --git a/.gitignore b/.gitignore index b196623..070a362 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ *.user *.sln.docstates .vs +.idea # Build results diff --git a/EFCache.Redis.Tests/EFCache.Redis.Tests.csproj b/EFCache.Redis.Tests/EFCache.Redis.Tests.csproj index eb13c2d..5c22b86 100644 --- a/EFCache.Redis.Tests/EFCache.Redis.Tests.csproj +++ b/EFCache.Redis.Tests/EFCache.Redis.Tests.csproj @@ -1,16 +1,16 @@  - net48 + net48;netcoreapp3.0 false - + - + diff --git a/EFCache.Redis.Tests/RedisCacheTests.cs b/EFCache.Redis.Tests/RedisCacheTests.cs index 11b1567..7ccfe79 100644 --- a/EFCache.Redis.Tests/RedisCacheTests.cs +++ b/EFCache.Redis.Tests/RedisCacheTests.cs @@ -28,7 +28,8 @@ public RedisCacheTests() try { // See if we have a running copy of redis in a K8s Cluster - // helm install --name redis-dev --set password=secretpassword --set master.disableCommands= stable/redis + // helm upgrade --install redis-dev --set password=secretpassword --set master.disableCommands= bitnami/redis + // kubectl get secret --namespace default redis-dev -o jsonpath="{.data.redis-password}" | base64 --decode // kubectl port-forward --namespace default svc/redis-dev-master 6379:6379 var connString = "localhost:6379,password=secretpassword"; @@ -38,12 +39,12 @@ public RedisCacheTests() AdminConnectionString = string.Join(",", connString, "allowAdmin=true"); } - catch (Exception) + catch(Exception) { // Could not connect to redis above, so start a local copy RedisStorageEmulatorManager.Instance.StartProcess(false); } - + } [TestMethod] @@ -98,7 +99,7 @@ public void Item_still_returned_after_sliding_expiration_period() object fromCache = null; // In a loop of 20 seconds retrieve the item every 5 second seconds. - for (var i = 0; i < 4; i++) + for(var i = 0; i < 4; i++) { Thread.Sleep(5000); // Wait 5 seconds // 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() Assert.AreEqual(0, cache.Count); } - + [TestMethod] public async Task ThreadingBlockTest() { @@ -167,8 +168,10 @@ public async Task ThreadingBlockTest() cache.CachingFailed += (sender, e) => { - if (e?.InnerException is LockTimeoutException) + if(e?.InnerException is LockTimeoutException) + { exception = e.InnerException; + } }; cache.Purge(); @@ -185,7 +188,7 @@ public async Task ThreadingBlockTest() var tasks = new Task[10]; - for (var i = 0; i < 10; i++) + for(var i = 0; i < 10; i++) { var icopy = i; tasks[i] = Task.Run(() => @@ -193,12 +196,13 @@ public async Task ThreadingBlockTest() var watch = new Stopwatch(); watch.Start(); Debug.WriteLine($"Invalidate {icopy} start"); - if (i == 9) + if(i == 9) + { cache.InvalidateItem("1"); + } else { - object val; - cache.GetItem("1", out val); + cache.GetItem("1", out var val); } watch.Stop(); Debug.WriteLine($"Invalidate {icopy} complete after {watch.ElapsedMilliseconds}"); @@ -211,8 +215,7 @@ public async Task ThreadingBlockTest() Debug.WriteLine($"Get start"); var watch = new Stopwatch(); watch.Start(); - object value; - cache.GetItem("1", out value); + cache.GetItem("1", out var value); watch.Stop(); Debug.WriteLine($"Get complete after {watch.ElapsedMilliseconds}"); }); @@ -227,10 +230,7 @@ public async Task ThreadingBlockTest() } - private void Cache_CachingFailed(object sender, RedisCacheException e) - { - throw new NotImplementedException(); - } + private void Cache_CachingFailed(object sender, RedisCacheException e) => throw new NotImplementedException(); [TestMethod] @@ -244,7 +244,7 @@ public void Count_does_not_return_expired_entries() cache.PutItem("1", new object(), new string[0], TimeSpan.MaxValue, DateTimeOffset.Now.AddSeconds(1)); - Assert.AreEqual(1, cache.Count); + Assert.AreEqual(1, cache.Count); Thread.Sleep(1000); @@ -282,31 +282,19 @@ public void GetItem_validates_parameters() [TestMethod] [ExpectedException(typeof(ArgumentOutOfRangeException))] - public void PutItem_validates_key_parameter() - { - new RedisCache(RegularConnectionString).PutItem(null, 42, new string[0], TimeSpan.Zero, DateTimeOffset.Now); - } + public void PutItem_validates_key_parameter() => new RedisCache(RegularConnectionString).PutItem(null, 42, new string[0], TimeSpan.Zero, DateTimeOffset.Now); [TestMethod] [ExpectedException(typeof(ArgumentNullException))] - public void PutItem_validates_dependentEntitySets_parameter() - { - new RedisCache(RegularConnectionString).PutItem("1", 42, null, TimeSpan.Zero, DateTimeOffset.Now); - } + public void PutItem_validates_dependentEntitySets_parameter() => new RedisCache(RegularConnectionString).PutItem("1", 42, null, TimeSpan.Zero, DateTimeOffset.Now); [TestMethod] [ExpectedException(typeof(ArgumentNullException))] - public void InvalidateSets_validates_parameters() - { - new RedisCache(RegularConnectionString).InvalidateSets(null); - } + public void InvalidateSets_validates_parameters() => new RedisCache(RegularConnectionString).InvalidateSets(null); [TestMethod] [ExpectedException(typeof(ArgumentOutOfRangeException))] - public void InvalidateItem_validates_parameters() - { - new RedisCache(RegularConnectionString).InvalidateItem(null); - } + public void InvalidateItem_validates_parameters() => new RedisCache(RegularConnectionString).InvalidateItem(null); [TestMethod] public void GetItem_does_not_crash_if_cache_is_unavailable() diff --git a/EFCache.Redis.Tests/StorageEmulatorManager.cs b/EFCache.Redis.Tests/StorageEmulatorManager.cs index 0bdf33d..5b250c4 100644 --- a/EFCache.Redis.Tests/StorageEmulatorManager.cs +++ b/EFCache.Redis.Tests/StorageEmulatorManager.cs @@ -24,11 +24,17 @@ protected StorageEmulatorManager(string processName, ProcessStartInfo processSta public void StartProcess(bool waitForExit) { - if (IsProcessStarted()) return; + if(IsProcessStarted()) + { + return; + } - using (var process = Process.Start(_processStartInfo)) + using(var process = Process.Start(_processStartInfo)) { - if (process != null && waitForExit) process.WaitForExit(); + if(process != null && waitForExit) + { + process.WaitForExit(); + } } } diff --git a/EFCache.Redis/EFCache.Redis.csproj b/EFCache.Redis/EFCache.Redis.csproj index 2b9808b..131fb0f 100644 --- a/EFCache.Redis/EFCache.Redis.csproj +++ b/EFCache.Redis/EFCache.Redis.csproj @@ -1,12 +1,12 @@  - net48 + net461;net472;net48;netstandard2.1 false - + diff --git a/EFCache.Redis/EFCache.Redis.nuspec b/EFCache.Redis/EFCache.Redis.nuspec index 744b9b1..0b567b2 100644 --- a/EFCache.Redis/EFCache.Redis.nuspec +++ b/EFCache.Redis/EFCache.Redis.nuspec @@ -2,7 +2,7 @@ EFCache.Redis - 2020.8.21.1 + 2020.8.21.2 Ian Robertson https://github.com/silentbobbert/EFCache.Redis https://avatars0.githubusercontent.com/u/3257988 @@ -12,7 +12,7 @@ EF6 EF6.3 Redis Caching L2 - + @@ -33,5 +33,7 @@ + + \ No newline at end of file diff --git a/EFCache.Redis/IRedisCache.cs b/EFCache.Redis/IRedisCache.cs index 2a6508f..889bc7e 100644 --- a/EFCache.Redis/IRedisCache.cs +++ b/EFCache.Redis/IRedisCache.cs @@ -1,5 +1,4 @@ -using EFCache; -using System; +using System; namespace EFCache.Redis { diff --git a/EFCache.Redis/Properties/AssemblyInfo.cs b/EFCache.Redis/Properties/AssemblyInfo.cs index 94bc969..5d79db2 100644 --- a/EFCache.Redis/Properties/AssemblyInfo.cs +++ b/EFCache.Redis/Properties/AssemblyInfo.cs @@ -31,6 +31,6 @@ // Build Number // Revision // -[assembly: AssemblyVersion("2020.8.21.1")] -[assembly: AssemblyFileVersion("2020.8.21.1")] +[assembly: AssemblyVersion("2020.11.9.1")] +[assembly: AssemblyFileVersion("2020.11.9.1")] diff --git a/EFCache.Redis/RedisCache.cs b/EFCache.Redis/RedisCache.cs index 0686eb5..58e987c 100644 --- a/EFCache.Redis/RedisCache.cs +++ b/EFCache.Redis/RedisCache.cs @@ -91,7 +91,10 @@ public bool GetItem(string key, out object value) OnCachingFailed(e); } - if (value == null) return false; + if (value == null) + { + return false; + } var entry = (CacheEntry)value; @@ -187,7 +190,11 @@ private TimeSpan GetTimeSpanExpiration(DateTimeOffset expiration) private static string HashKey(string key) { //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 - if (key.Length <= 128) return key; + if (key.Length <= 128) + { + return key; + } + using (var sha = new SHA1CryptoServiceProvider()) { key = Convert.ToBase64String(sha.ComputeHash(Encoding.UTF8.GetBytes(key))); @@ -244,7 +251,10 @@ public void InvalidateItem(string key) { var entry = _database.Get(key); - if (entry == null) return; + if (entry == null) + { + return; + } _database.KeyDelete(key, CommandFlags.FireAndForget); diff --git a/EFCache.Redis/StackExchangeRedisExtensions.cs b/EFCache.Redis/StackExchangeRedisExtensions.cs index 3c4a105..484e3a0 100644 --- a/EFCache.Redis/StackExchangeRedisExtensions.cs +++ b/EFCache.Redis/StackExchangeRedisExtensions.cs @@ -21,7 +21,11 @@ public static void Set(this IDatabase cache, string key, T value, TimeSpan ex static byte[] Serialize(T o) where T : class { - if (o == null) return null; + if (o == null) + { + return null; + } + var binaryFormatter = new BinaryFormatter(); using (var memoryStream = new MemoryStream()) @@ -34,7 +38,11 @@ static byte[] Serialize(T o) where T : class static T Deserialize(byte[] stream) { - if (stream == null || !stream.Any()) return default(T); + if (stream == null || !stream.Any()) + { + return default(T); + } + var binaryFormatter = new BinaryFormatter(); using (var memoryStream = new MemoryStream(stream)) { diff --git a/EFCache.Redis/packages.config b/EFCache.Redis/packages.config deleted file mode 100644 index 92cf61a..0000000 --- a/EFCache.Redis/packages.config +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file