Letting Memory Cache takes care of the locks cause of concurrent requ…#115
Open
paulcaru wants to merge 5 commits intoconductor-oss:mainfrom
Open
Letting Memory Cache takes care of the locks cause of concurrent requ…#115paulcaru wants to merge 5 commits intoconductor-oss:mainfrom
paulcaru wants to merge 5 commits intoconductor-oss:mainfrom
Conversation
1) All Waiting for Lock if Token is Null 2) First goes in Checks Again Memory Cache 3) Nothing is found and calls GetTokenFromServer and fetches token 4) Lock is released and 2nd one goes in. checks Memory Cache and its found 5) Return Token
1) All Waiting for Lock if Token is Null 2) First goes in Checks Again Memory Cache 3) Nothing is found and calls GetTokenFromServer and fetches token 4) Lock is released and 2nd one goes in. checks Memory Cache and its found 5) Return Token
IvanKulik-sm
requested changes
Jul 16, 2025
| } | ||
| return RefreshToken(authenticationSettings, tokenClient); | ||
|
|
||
| lock (_getTokenlockObject) |
Contributor
There was a problem hiding this comment.
Something like this should be used:
string token = _memoryCache.GetOrCreate(authenticationSettings, entry =>
{
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(30);
return GetTokenFromServer(authenticationSettings, tokenClient);
});
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Improving GetToken Method by removing lock and letting Microsoft Memory Cache handle this as it wasn't handled well for concurrency