Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

always use utc to compare the expiry #495

Merged
merged 1 commit into from
Oct 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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