diff --git a/src/dotnet/Common/Services/ResourceProviders/ResourceProviderResourceCacheService.cs b/src/dotnet/Common/Services/ResourceProviders/ResourceProviderResourceCacheService.cs index b10cad677..9b69ae76b 100644 --- a/src/dotnet/Common/Services/ResourceProviders/ResourceProviderResourceCacheService.cs +++ b/src/dotnet/Common/Services/ResourceProviders/ResourceProviderResourceCacheService.cs @@ -29,7 +29,7 @@ public void SetValue(ResourceReference resourceReference, T resourceValue) wh { try { - _cache.Set(resourceReference, resourceValue, _cacheEntryOptions); + _cache.Set(GetCacheKey(resourceReference), resourceValue, _cacheEntryOptions); _logger.LogInformation("The resource {ResourceName} of type {ResourceType} has been set in the cache.", resourceReference.Name, resourceReference.Type); @@ -49,7 +49,7 @@ public bool TryGetValue(ResourceReference resourceReference, out T? resourceV try { - if (_cache.TryGetValue(resourceReference, out T? cachedValue) + if (_cache.TryGetValue(GetCacheKey(resourceReference), out T? cachedValue) && cachedValue != null) { resourceValue = cachedValue; @@ -68,5 +68,8 @@ public bool TryGetValue(ResourceReference resourceReference, out T? resourceV return false; } + + private string GetCacheKey(ResourceReference resourceReference) => + $"{resourceReference.Type}|{resourceReference.Name}"; } }