Skip to content

Commit

Permalink
Improve cache key generation
Browse files Browse the repository at this point in the history
  • Loading branch information
ciprianjichici committed Dec 11, 2024
1 parent 8040047 commit 6aafd5a
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void SetValue<T>(ResourceReference resourceReference, T resourceValue) wh
{
try
{
_cache.Set<T>(resourceReference, resourceValue, _cacheEntryOptions);
_cache.Set<T>(GetCacheKey(resourceReference), resourceValue, _cacheEntryOptions);
_logger.LogInformation("The resource {ResourceName} of type {ResourceType} has been set in the cache.",
resourceReference.Name,
resourceReference.Type);
Expand All @@ -49,7 +49,7 @@ public bool TryGetValue<T>(ResourceReference resourceReference, out T? resourceV

try
{
if (_cache.TryGetValue<T>(resourceReference, out T? cachedValue)
if (_cache.TryGetValue<T>(GetCacheKey(resourceReference), out T? cachedValue)
&& cachedValue != null)
{
resourceValue = cachedValue;
Expand All @@ -68,5 +68,8 @@ public bool TryGetValue<T>(ResourceReference resourceReference, out T? resourceV

return false;
}

private string GetCacheKey(ResourceReference resourceReference) =>
$"{resourceReference.Type}|{resourceReference.Name}";
}
}

0 comments on commit 6aafd5a

Please sign in to comment.