1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-05 13:08:17 -05:00

Switch to UtcDateTime (#4710)

This commit is contained in:
Justin Baur 2024-08-29 10:27:41 -04:00 committed by GitHub
parent 0d61f30d53
commit d4122d1fb6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -38,7 +38,7 @@ public class EntityFrameworkCache : IDistributedCache
using var scope = _serviceScopeFactory.CreateScope();
var dbContext = GetDatabaseContext(scope);
var cache = dbContext.Cache
.Where(c => c.Id == key && _timeProvider.GetUtcNow().DateTime <= c.ExpiresAtTime)
.Where(c => c.Id == key && _timeProvider.GetUtcNow().UtcDateTime <= c.ExpiresAtTime)
.SingleOrDefault();
if (cache == null)
@ -63,7 +63,7 @@ public class EntityFrameworkCache : IDistributedCache
using var scope = _serviceScopeFactory.CreateScope();
var dbContext = GetDatabaseContext(scope);
var cache = await dbContext.Cache
.Where(c => c.Id == key && _timeProvider.GetUtcNow().DateTime <= c.ExpiresAtTime)
.Where(c => c.Id == key && _timeProvider.GetUtcNow().UtcDateTime <= c.ExpiresAtTime)
.SingleOrDefaultAsync(cancellationToken: token);
if (cache == null)
@ -185,7 +185,7 @@ public class EntityFrameworkCache : IDistributedCache
private Cache SetCache(Cache? cache, string key, byte[] value, DistributedCacheEntryOptions options)
{
var utcNow = _timeProvider.GetUtcNow().DateTime;
var utcNow = _timeProvider.GetUtcNow().UtcDateTime;
// resolve options
if (!options.AbsoluteExpiration.HasValue &&
@ -219,7 +219,7 @@ public class EntityFrameworkCache : IDistributedCache
throw new InvalidOperationException("The absolute expiration value must be in the future.");
}
absoluteExpiration = options.AbsoluteExpiration.Value.DateTime;
absoluteExpiration = options.AbsoluteExpiration.Value.UtcDateTime;
}
// set values on cache
@ -244,7 +244,7 @@ public class EntityFrameworkCache : IDistributedCache
private bool UpdateCacheExpiration(Cache cache)
{
var utcNow = _timeProvider.GetUtcNow().DateTime;
var utcNow = _timeProvider.GetUtcNow().UtcDateTime;
if (cache.SlidingExpirationInSeconds.HasValue && (cache.AbsoluteExpiration.HasValue || cache.AbsoluteExpiration != cache.ExpiresAtTime))
{
if (cache.AbsoluteExpiration.HasValue && (cache.AbsoluteExpiration.Value - utcNow).TotalSeconds <= cache.SlidingExpirationInSeconds)
@ -264,7 +264,7 @@ public class EntityFrameworkCache : IDistributedCache
{
lock (_mutex)
{
var utcNow = _timeProvider.GetUtcNow().DateTime;
var utcNow = _timeProvider.GetUtcNow().UtcDateTime;
if ((utcNow - _lastExpirationScan) > _expiredItemsDeletionInterval)
{
_lastExpirationScan = utcNow;
@ -280,7 +280,7 @@ public class EntityFrameworkCache : IDistributedCache
{
using var scope = _serviceScopeFactory.CreateScope();
GetDatabaseContext(scope).Cache
.Where(c => _timeProvider.GetUtcNow().DateTime > c.ExpiresAtTime)
.Where(c => _timeProvider.GetUtcNow().UtcDateTime > c.ExpiresAtTime)
.ExecuteDelete();
}