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

EasyCaching in Multitenant application #445

Open
umar-ulabs opened this issue Jan 14, 2023 · 2 comments
Open

EasyCaching in Multitenant application #445

umar-ulabs opened this issue Jan 14, 2023 · 2 comments
Labels

Comments

@umar-ulabs
Copy link

I been using EasyCaching by adding one global instance and passing tenant id as Key (to isolate data) to each caching method. If I add EasyCaching service per tenant scope. So each tenant will get full EasyCaching instance, will that be better or one global service is enough?
Thanks for your insights.

@catcherwong
Copy link
Member

@umar-ulabs Thanks for your interest in this project.

Based on your description, one global service is enough.

But if you want to separate them, you can use IEasyCachingFactory to get providers with different configuration.

Here is an example,

services.AddEasyCaching(option =>
{
    option..WithMessagePack("mymsgpack");
    option.UseRedis(config =>
    {
        config.DBConfig.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6379));
        config.SerializerName = "mymsgpack";
    }, "tenant-a");

    option.UseRedis(config =>
    {
        config.DBConfig.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6380));
        config.SerializerName = "mymsgpack";
    }, "tenant-b");   
});

// get IEasyCachingProviderFactory
var factory = app.ApplicationServices.GetRequiredService<EasyCaching.Core.IEasyCachingProviderFactory>();
// get provider with different tenant
var provider = factory.GetCachingProvider("tenant-a");
// call methods
provider.xxxx

@umar-ulabs
Copy link
Author

So essentially I can add easycache per tenant? thanks. I hesitated doing that because if I have 500 tenants it will add/maintain 500 instances of easycache. As long as its ok. I would love to add it, rather than passing tenant id for each methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants