Skip to content

Commit

Permalink
Merge pull request #495 from bdidier/dev
Browse files Browse the repository at this point in the history
always use utc to compare the expiry
  • Loading branch information
Memoyu authored Oct 7, 2023
2 parents 244cb24 + 125917a commit 2fd7fdc
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/EasyCaching.LiteDB/DefaultLiteDBCachingProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public override bool BaseExists(string cacheKey)
{
ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey));

var dbResult = _cache.Count(fc => fc.cachekey == cacheKey && fc.expiration > DateTimeOffset.Now.ToUnixTimeSeconds());
var dbResult = _cache.Count(fc => fc.cachekey == cacheKey && fc.expiration > DateTimeOffset.UtcNow.ToUnixTimeSeconds());

return dbResult > 0;
}
Expand All @@ -131,7 +131,7 @@ public override CacheValue<T> BaseGet<T>(string cacheKey, Func<T> dataRetriever,
ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey));
ArgumentCheck.NotNegativeOrZero(expiration, nameof(expiration));

var cacheItem = _cache.FindOne(c => c.cachekey == cacheKey && c.expiration > DateTimeOffset.Now.ToUnixTimeSeconds());
var cacheItem = _cache.FindOne(c => c.cachekey == cacheKey && c.expiration > DateTimeOffset.UtcNow.ToUnixTimeSeconds());

if (cacheItem != null)
{
Expand Down Expand Up @@ -164,7 +164,7 @@ public override CacheValue<T> BaseGet<T>(string cacheKey)
{
ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey));

var cacheItem = _cache.FindOne(c => c.cachekey == cacheKey && c.expiration > DateTimeOffset.Now.ToUnixTimeSeconds());
var cacheItem = _cache.FindOne(c => c.cachekey == cacheKey && c.expiration > DateTimeOffset.UtcNow.ToUnixTimeSeconds());

if (cacheItem != null || _options.CacheNulls)
{
Expand Down Expand Up @@ -317,7 +317,7 @@ public override IDictionary<string, CacheValue<T>> BaseGetAll<T>(IEnumerable<str
{
ArgumentCheck.NotNullAndCountGTZero(cacheKeys, nameof(cacheKeys));
var lst = cacheKeys.ToList();
var list = _cache.Find(c => lst.Contains(c.cachekey) && c.expiration > DateTimeOffset.Now.ToUnixTimeSeconds()).ToList();
var list = _cache.Find(c => lst.Contains(c.cachekey) && c.expiration > DateTimeOffset.UtcNow.ToUnixTimeSeconds()).ToList();
return GetDict<T>(list);
}

Expand Down Expand Up @@ -354,7 +354,7 @@ private IDictionary<string, CacheValue<T>> GetDict<T>(List<CacheItem> list)
public override IDictionary<string, CacheValue<T>> BaseGetByPrefix<T>(string prefix)
{
ArgumentCheck.NotNullOrWhiteSpace(prefix, nameof(prefix));
var list = _cache.Find(c => c.cachekey.StartsWith(prefix) && c.expiration > DateTimeOffset.Now.ToUnixTimeSeconds()).ToList();
var list = _cache.Find(c => c.cachekey.StartsWith(prefix) && c.expiration > DateTimeOffset.UtcNow.ToUnixTimeSeconds()).ToList();
return GetDict<T>(list);
}

Expand All @@ -380,11 +380,11 @@ public override int BaseGetCount(string prefix = "")
{
if (string.IsNullOrWhiteSpace(prefix))
{
return _cache.Count(c => c.expiration > DateTimeOffset.Now.ToUnixTimeSeconds());
return _cache.Count(c => c.expiration > DateTimeOffset.UtcNow.ToUnixTimeSeconds());
}
else
{
return _cache.Count(c => c.cachekey.StartsWith(prefix) && c.expiration > DateTimeOffset.Now.ToUnixTimeSeconds());
return _cache.Count(c => c.cachekey.StartsWith(prefix) && c.expiration > DateTimeOffset.UtcNow.ToUnixTimeSeconds());
}
}

Expand Down Expand Up @@ -413,7 +413,7 @@ public override bool BaseTrySet<T>(string cacheKey, T cacheValue, TimeSpan expir
expiration.Add(new TimeSpan(0, 0, addSec));
}

var r = _cache.FindOne(c => c.cachekey == cacheKey && c.expiration > DateTimeOffset.Now.ToUnixTimeSeconds());
var r = _cache.FindOne(c => c.cachekey == cacheKey && c.expiration > DateTimeOffset.UtcNow.ToUnixTimeSeconds());
bool result = false;
if (r == null)
{
Expand Down

0 comments on commit 2fd7fdc

Please sign in to comment.