Skip to content

Commit

Permalink
fix: fixed cache unll value judgment of SQLLite BaseGet
Browse files Browse the repository at this point in the history
  • Loading branch information
Memoyu committed Nov 20, 2023
1 parent ff350ba commit 2f94291
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/EasyCaching.SQLite/DefaultSQLiteCachingProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ public DefaultSQLiteCachingProvider(
/// </summary>
/// <param name="dbProvider"></param>
private void InitDb(ISQLiteDatabaseProvider dbProvider)
{
{
var conn = dbProvider.GetConnection();

if (conn.State == System.Data.ConnectionState.Closed)
{
conn.Open();
}

conn.Execute(ConstSQL.CREATESQL);
conn.Execute(ConstSQL.CREATESQL);
}

/// <summary>
Expand Down Expand Up @@ -159,16 +159,16 @@ public override CacheValue<T> BaseGet<T>(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<T>(dbResult);
return cacheValue == null
? CacheValue<T>.Null
: new CacheValue<T>(Newtonsoft.Json.JsonConvert.DeserializeObject<T>(dbResult), true);
: new CacheValue<T>(cacheValue, true);
}
else
{
Expand Down Expand Up @@ -221,7 +221,7 @@ public override void BaseSet<T>(string cacheKey, T cacheValue, TimeSpan expirati
expiration = expiration.Ticks / 10000000
});

}
}

/// <summary>
/// Removes cached item by cachekey's prefix.
Expand All @@ -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 });
}

/// <summary>
/// Sets all.
/// </summary>
Expand All @@ -276,7 +276,7 @@ public override void BaseSetAll<T>(IDictionary<string, T> values, TimeSpan expir
}

tran.Commit();
}
}

/// <summary>
/// Gets all.
Expand Down Expand Up @@ -339,7 +339,7 @@ public override IDictionary<string, CacheValue<T>> BaseGetByPrefix<T>(string pre

return GetDict<T>(list);
}

/// <summary>
/// Removes all.
/// </summary>
Expand Down

0 comments on commit 2f94291

Please sign in to comment.