Skip to content

Commit

Permalink
refactor: fix caching issue when aggregate is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
jacqueskang committed Feb 15, 2020
1 parent 3b6f9e5 commit 1a8c23b
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,24 @@ protected override async Task<TAggregate> FindAggregateAsync(
int version = -1,
CancellationToken cancellationToken = default)
{
string key = GetCacheKey(id, version);
string serialized = await _cache.GetStringAsync(key, cancellationToken).ConfigureAwait(false);
if (!string.IsNullOrEmpty(serialized))
try
{
return DeserializeAggregate(serialized);
string key = GetCacheKey(id, version);
string serialized = await _cache.GetStringAsync(key, cancellationToken).ConfigureAwait(false);
if (!string.IsNullOrEmpty(serialized))
{
return DeserializeAggregate(serialized);
}
}
catch { }

TAggregate aggregate = await base.FindAggregateAsync(id, ignoreSnapshot, version, cancellationToken)
.ConfigureAwait(false);

await CacheAsync(aggregate, version, cancellationToken).ConfigureAwait(false);
if (aggregate != null)
{
await CacheAsync(aggregate, version, cancellationToken).ConfigureAwait(false);
}

return aggregate;
}
Expand Down

0 comments on commit 1a8c23b

Please sign in to comment.