Skip to content

Commit

Permalink
Remove unnecessary deserialization actions
Browse files Browse the repository at this point in the history
  • Loading branch information
hyzx86 authored Dec 15, 2023
1 parent f28560f commit ab49286
Showing 1 changed file with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -364,23 +364,20 @@ protected async Task InvalidateInternalAsync(TDocument document, bool failover =

private async Task<TDocument> GetFromDistributedCacheAsync()
{
byte[] data = null;

if (_isDistributed)
{
data = await _distributedCache.GetAsync(_options.CacheKey);
byte[] data = await _distributedCache.GetAsync(_options.CacheKey);
if (data == null)
{
return null;
}
return await _options.Serializer.DeserializeAsync<TDocument>(data);
}
else if (_memoryCache.TryGetValue<TDocument>(_options.CacheKey, out var cached))
{
data = await _options.Serializer.SerializeAsync(cached);
}

if (data == null)
{
return null;
return cached;
}

return await _options.Serializer.DeserializeAsync<TDocument>(data);
return null;
}

private async Task UpdateDistributedCacheAsync(TDocument document)
Expand Down

0 comments on commit ab49286

Please sign in to comment.