From 2f94291a2aba950711cd722b35d71607bb91d2a3 Mon Sep 17 00:00:00 2001 From: Memoyu Date: Mon, 20 Nov 2023 22:34:38 +0800 Subject: [PATCH] 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. ///