From 3166fee4d1e9fac83865f8b59232a2f08aad1b94 Mon Sep 17 00:00:00 2001 From: Memoyu Date: Sat, 18 Nov 2023 11:13:07 +0800 Subject: [PATCH 1/4] fix: update CacheNulls to true #506 --- src/EasyCaching.Core/Configurations/BaseProviderOptions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EasyCaching.Core/Configurations/BaseProviderOptions.cs b/src/EasyCaching.Core/Configurations/BaseProviderOptions.cs index 3ec88f96..b1d2dfe2 100644 --- a/src/EasyCaching.Core/Configurations/BaseProviderOptions.cs +++ b/src/EasyCaching.Core/Configurations/BaseProviderOptions.cs @@ -42,8 +42,8 @@ public class BaseProviderOptions public string SerializerName { get; set; } /// - /// Get or sets whether null values should be cached, default is false. + /// Get or sets whether null values should be cached, default is true. /// - public bool CacheNulls { get; set; } = false; + public bool CacheNulls { get; set; } = true; } } From ff350baebcdc095349394bf2e9192aa28fc4735a Mon Sep 17 00:00:00 2001 From: Memoyu Date: Sun, 19 Nov 2023 23:04:31 +0800 Subject: [PATCH 2/4] fix: update baset test version to 1.9.3 --- .../CachingTests/MemoryCachingProviderTest.cs | 5 ++--- test/EasyCaching.UnitTests/EasyCaching.UnitTests.csproj | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/test/EasyCaching.UnitTests/CachingTests/MemoryCachingProviderTest.cs b/test/EasyCaching.UnitTests/CachingTests/MemoryCachingProviderTest.cs index 0795a6ea..511e5f2d 100644 --- a/test/EasyCaching.UnitTests/CachingTests/MemoryCachingProviderTest.cs +++ b/test/EasyCaching.UnitTests/CachingTests/MemoryCachingProviderTest.cs @@ -1,8 +1,7 @@ -using EasyCaching.Core.Configurations; -using EasyCaching.Core.DistributedLock; - namespace EasyCaching.UnitTests { + using EasyCaching.Core.Configurations; + using EasyCaching.Core.DistributedLock; using EasyCaching.Core; using EasyCaching.InMemory; using Microsoft.Extensions.Configuration; diff --git a/test/EasyCaching.UnitTests/EasyCaching.UnitTests.csproj b/test/EasyCaching.UnitTests/EasyCaching.UnitTests.csproj index b1f6327f..f605ef48 100644 --- a/test/EasyCaching.UnitTests/EasyCaching.UnitTests.csproj +++ b/test/EasyCaching.UnitTests/EasyCaching.UnitTests.csproj @@ -17,7 +17,7 @@ - + From 2f94291a2aba950711cd722b35d71607bb91d2a3 Mon Sep 17 00:00:00 2001 From: Memoyu Date: Mon, 20 Nov 2023 22:34:38 +0800 Subject: [PATCH 3/4] fix: fixed cache unll value judgment of SQLLite BaseGet --- .../DefaultSQLiteCachingProvider.cs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/EasyCaching.SQLite/DefaultSQLiteCachingProvider.cs b/src/EasyCaching.SQLite/DefaultSQLiteCachingProvider.cs index 95a76d68..3a47ca7b 100644 --- a/src/EasyCaching.SQLite/DefaultSQLiteCachingProvider.cs +++ b/src/EasyCaching.SQLite/DefaultSQLiteCachingProvider.cs @@ -85,7 +85,7 @@ public DefaultSQLiteCachingProvider( /// /// private void InitDb(ISQLiteDatabaseProvider dbProvider) - { + { var conn = dbProvider.GetConnection(); if (conn.State == System.Data.ConnectionState.Closed) @@ -93,7 +93,7 @@ private void InitDb(ISQLiteDatabaseProvider dbProvider) conn.Open(); } - conn.Execute(ConstSQL.CREATESQL); + conn.Execute(ConstSQL.CREATESQL); } /// @@ -159,16 +159,16 @@ public override CacheValue BaseGet(string cacheKey) name = _name }).FirstOrDefault(); - if (!string.IsNullOrWhiteSpace(dbResult) || _options.CacheNulls) + if (!string.IsNullOrWhiteSpace(dbResult)) { CacheStats.OnHit(); if (_options.EnableLogging) _logger?.LogInformation($"Cache Hit : cachekey = {cacheKey}"); - - return string.IsNullOrWhiteSpace(dbResult) + var cacheValue = Newtonsoft.Json.JsonConvert.DeserializeObject(dbResult); + return cacheValue == null ? CacheValue.Null - : new CacheValue(Newtonsoft.Json.JsonConvert.DeserializeObject(dbResult), true); + : new CacheValue(cacheValue, true); } else { @@ -221,7 +221,7 @@ public override void BaseSet(string cacheKey, T cacheValue, TimeSpan expirati expiration = expiration.Ticks / 10000000 }); - } + } /// /// Removes cached item by cachekey's prefix. @@ -247,10 +247,10 @@ public override void BaseRemoveByPattern(string pattern) if (_options.EnableLogging) _logger?.LogInformation($"RemoveByPattern : pattern = {pattern}"); - + _cache.Execute(ConstSQL.REMOVEBYLIKESQL, new { cachekey = pattern.Replace('*', '%'), name = _name }); } - + /// /// Sets all. /// @@ -276,7 +276,7 @@ public override void BaseSetAll(IDictionary values, TimeSpan expir } tran.Commit(); - } + } /// /// Gets all. @@ -339,7 +339,7 @@ public override IDictionary> BaseGetByPrefix(string pre return GetDict(list); } - + /// /// Removes all. /// From e5a0f72cf5fe3d379f665f27372fe37cf8ff6606 Mon Sep 17 00:00:00 2001 From: Memoyu Date: Mon, 20 Nov 2023 22:48:09 +0800 Subject: [PATCH 4/4] fixed cache unll value judgment of LiteDB BaseGet --- src/EasyCaching.LiteDB/DefaultLiteDBCachingProvider.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EasyCaching.LiteDB/DefaultLiteDBCachingProvider.cs b/src/EasyCaching.LiteDB/DefaultLiteDBCachingProvider.cs index bf2e5809..19d277d4 100644 --- a/src/EasyCaching.LiteDB/DefaultLiteDBCachingProvider.cs +++ b/src/EasyCaching.LiteDB/DefaultLiteDBCachingProvider.cs @@ -166,14 +166,14 @@ public override CacheValue BaseGet(string cacheKey) var cacheItem = _cache.FindOne(c => c.cachekey == cacheKey && c.expiration > DateTimeOffset.UtcNow.ToUnixTimeSeconds()); - if (cacheItem != null || _options.CacheNulls) + if (cacheItem != null) { if (_options.EnableLogging) _logger?.LogInformation($"Cache Hit : cachekey = {cacheKey}"); CacheStats.OnHit(); - return string.IsNullOrWhiteSpace(cacheItem?.cachevalue) + return cacheItem.cachevalue == null ? CacheValue.Null : new CacheValue(Newtonsoft.Json.JsonConvert.DeserializeObject(cacheItem.cachevalue), true); }