Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(graphql): Disable in-memory cache for authorized parties #1531

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,25 @@ public async Task<AuthorizedPartiesResult> GetAuthorizedParties(IPartyIdentifier
var authorizedParties = await _partiesCache.GetOrSetAsync(cacheKey, async token
=> await PerformAuthorizedPartiesRequest(authorizedPartiesRequest, token), token: cancellationToken);

var mcaField = typeof(FusionCache).GetField("_mca", BindingFlags.NonPublic | BindingFlags.Instance);
var mcaValue = mcaField?.GetValue(_partiesCache);
var mcField = mcaValue!.GetType().GetField("_cache", BindingFlags.NonPublic | BindingFlags.Instance);
var mcValue = mcField?.GetValue(mcaValue) as IMemoryCache;

var inMemoryCacheValue = mcValue!.TryGetValue(cacheKey, out var inMemoryCacheEntry);
var inMemoryCacheEntryValue = inMemoryCacheEntry?.GetType().GetProperty("Value")?.GetValue(inMemoryCacheEntry);
// Testing https://github.com/digdir/dialogporten/issues/1226
try
{
var mcaField = typeof(FusionCache).GetField("_mca", BindingFlags.NonPublic | BindingFlags.Instance);
var mcaValue = mcaField?.GetValue(_partiesCache);
var mcField = mcaValue!.GetType().GetField("_cache", BindingFlags.NonPublic | BindingFlags.Instance);
var mcValue = mcField?.GetValue(mcaValue) as IMemoryCache;

_logger.LogInformation("In memory cache value for {CacheKey}, success: {InMemoryCacheValue} value: {@inMemoryCacheEntryValue}",
cacheKey, inMemoryCacheValue, inMemoryCacheEntryValue);
var inMemoryCacheValue = mcValue!.TryGetValue(cacheKey, out var inMemoryCacheEntry);
var inMemoryCacheEntryValue = inMemoryCacheEntry?.GetType().GetProperty("Value")?.GetValue(inMemoryCacheEntry);

_logger.LogInformation("In memory cache value for {CacheKey}, success: {InMemoryCacheValue} value: {@inMemoryCacheEntryValue}",
cacheKey, inMemoryCacheValue, inMemoryCacheEntryValue);
}
catch (Exception e)
{
_logger.LogError(e, "Failed to reflect on FusionCache MemoryCache");
}

// Temporary logging to debug missing authorized sub parties
_logger.LogInformation("Authorized parties for {Party}: {@AuthorizedParties}", authenticatedParty, authorizedParties);

return flatten ? GetFlattenedAuthorizedParties(authorizedParties) : authorizedParties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ internal static void AddInfrastructure_Internal(InfrastructureBuilderContext bui
})
.ConfigureFusionCache(nameof(AuthorizedPartiesResult), new()
{
// Testing https://github.com/digdir/dialogporten/issues/1226
SkipMemoryCache = true,
// We keep authorized parties in a separate cache key, as this originates from a different API
// and has lees cardinality than the dialog authorization cache (only one per user). We therefore
// allow a memory cache for this.
Expand Down
Loading