Skip to content

Commit 2fd7fdc

Browse files
authored
Merge pull request #495 from bdidier/dev
always use utc to compare the expiry
2 parents 244cb24 + 125917a commit 2fd7fdc

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/EasyCaching.LiteDB/DefaultLiteDBCachingProvider.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public override bool BaseExists(string cacheKey)
113113
{
114114
ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey));
115115

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

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

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

136136
if (cacheItem != null)
137137
{
@@ -164,7 +164,7 @@ public override CacheValue<T> BaseGet<T>(string cacheKey)
164164
{
165165
ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey));
166166

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

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

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

@@ -380,11 +380,11 @@ public override int BaseGetCount(string prefix = "")
380380
{
381381
if (string.IsNullOrWhiteSpace(prefix))
382382
{
383-
return _cache.Count(c => c.expiration > DateTimeOffset.Now.ToUnixTimeSeconds());
383+
return _cache.Count(c => c.expiration > DateTimeOffset.UtcNow.ToUnixTimeSeconds());
384384
}
385385
else
386386
{
387-
return _cache.Count(c => c.cachekey.StartsWith(prefix) && c.expiration > DateTimeOffset.Now.ToUnixTimeSeconds());
387+
return _cache.Count(c => c.cachekey.StartsWith(prefix) && c.expiration > DateTimeOffset.UtcNow.ToUnixTimeSeconds());
388388
}
389389
}
390390

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

416-
var r = _cache.FindOne(c => c.cachekey == cacheKey && c.expiration > DateTimeOffset.Now.ToUnixTimeSeconds());
416+
var r = _cache.FindOne(c => c.cachekey == cacheKey && c.expiration > DateTimeOffset.UtcNow.ToUnixTimeSeconds());
417417
bool result = false;
418418
if (r == null)
419419
{

0 commit comments

Comments
 (0)