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

MultiTenant breaks OutputCache EvictCacheAsync() #7

Open
brettwinters opened this issue Sep 26, 2024 · 0 comments
Open

MultiTenant breaks OutputCache EvictCacheAsync() #7

brettwinters opened this issue Sep 26, 2024 · 0 comments

Comments

@brettwinters
Copy link

brettwinters commented Sep 26, 2024

Hi @myquay

The issue occurs if OutputCache is used alongside your library.

This is an odd one which has me stumped - I've attached a minimal project to demonstrate

When you configure the OutputCache outside the tenant container

builder
	.Services
	.AddOutputCache(options => options
		.AddBasePolicy(config => config.Tag("TagA").Expire(TimeSpan.FromSeconds(10)))
	);

This sets up a singleton for the IOutputCacheStore as follows:

public static IServiceCollection AddOutputCache(this IServiceCollection services)
    {
        ArgumentNullException.ThrowIfNull(services);

        services.AddTransient<IConfigureOptions<OutputCacheOptions>, OutputCacheOptionsSetup>();

        services.TryAddSingleton<ObjectPoolProvider, DefaultObjectPoolProvider>();

        services.TryAddSingleton<IOutputCacheStore>(sp =>
        {
            var outputCacheOptions = sp.GetRequiredService<IOptions<OutputCacheOptions>>();
            return new MemoryOutputCacheStore(new MemoryCache(new MemoryCacheOptions
            {
                SizeLimit = outputCacheOptions.Value.SizeLimit
            }));
        });
        return services;
    }

But when you evict the cache using it's tag inside the tenant container as follows:

public void Handle()
{
    _cacheStore.EvictByTagAsync("TagA", CancellationToken.None);
}

The _cacheStore is always empty. I checked the hashcode in the Post handler and my command handler and it looks like the same instance

When commenting out the Multitenant container and calling the Handle() normally in the main service container it works fine.

Here the minimal project

WebApplication1.zip

@brettwinters brettwinters changed the title MultiTenant breaks OutputCache EventCacheAsync() MultiTenant breaks OutputCache EvictCacheAsync() Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant