Skip to content

Commit

Permalink
Cache and weakrefkey fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tippmar-nr committed Dec 11, 2024
1 parent 8baf706 commit 0a5cb25
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public LRUCache(int capacity)

public TValue Get(TKey key)
{
_lock.EnterReadLock();
_lock.EnterUpgradeableReadLock();
try
{
if (_cacheMap.TryGetValue(key, out var node))
Expand All @@ -55,7 +55,7 @@ public TValue Get(TKey key)
}
finally
{
_lock.ExitReadLock();
_lock.ExitUpgradeableReadLock();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace NewRelic.Agent.Extensions.Caching
/// <typeparam name="T"></typeparam>
public class WeakReferenceKey<T> where T : class
{
public WeakReference<T> WeakReference { get; }
private WeakReference<T> WeakReference { get; }

public WeakReferenceKey(T cacheKey)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ private ArnBuilder CreateArnBuilder(IAgent agent, dynamic requestContext)
return new ArnBuilder(partition, systemName, accountId);
}

private string GetAccountId(IAgent agent, dynamic clientConfig)
private string GetAccountId(IAgent agent, object clientConfig)
{
var cacheKey = new WeakReferenceKey<object>(clientConfig);
string accountId = AmazonServiceClientWrapper.AwsAccountIdByClientConfigCache.ContainsKey(cacheKey) ? (string)AmazonServiceClientWrapper.AwsAccountIdByClientConfigCache.Get(clientConfig) : agent.Configuration.AwsAccountId;
string accountId = AmazonServiceClientWrapper.AwsAccountIdByClientConfigCache.ContainsKey(cacheKey) ? AmazonServiceClientWrapper.AwsAccountIdByClientConfigCache.Get(cacheKey) : agent.Configuration.AwsAccountId;

if (accountId != null)
{
Expand Down

0 comments on commit 0a5cb25

Please sign in to comment.