fix: exception if value is null
All checks were successful
.NET Test Pipeline / build-and-test (pull_request) Successful in 2m53s

This commit is contained in:
Polianin Nikita 2024-06-28 01:49:45 +03:00
parent 8d4c482bbd
commit 612efcb91c

View File

@ -23,8 +23,11 @@ public class MemoryCacheService(IMemoryCache cache) : ICacheService
public Task<T?> GetAsync<T>(string key, CancellationToken cancellationToken = default)
{
cache.TryGetValue(key, out byte[]? value);
return Task.FromResult(JsonSerializer.Deserialize<T>(value));
return Task.FromResult(
cache.TryGetValue(key, out byte[]? value) ?
JsonSerializer.Deserialize<T>(value) :
default
);
}
public Task RemoveAsync(string key, CancellationToken cancellationToken = default)