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

WIP Multi-Tenancy: Separate second-level cache per tenant (prototype for discussion) #2133

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

bahusoid
Copy link
Member

@bahusoid bahusoid commented Apr 16, 2019

This is prototype just for discussion so please ignore any breaking or non-functional changes
Follow up to #2108

I think we should create separate cache per tenant for better data separation and to allow tenant specific cache clean up (must have feature from my multi-tenant experience) and other actions (like ISessionFactory.EvictEntity, EvictCollection, ....). Without this change BulkOperationCleanupAction cleans up cache for all tenants when it's executed for some specific tenant. I don't see that it's somehow handled in hibernate so seems they clean cache for all tenants too (also found related complaints here)

So my idea is to create cache dynamically by tenantIdentifier and provide to persisters cache creation delegate instead of already created instance of cache.

Some pending questions if you agree with this plan:

  1. Should we still keep tenantIdentifier as part of CacheKey?
    me: for now seems unnecessary.
  2. Should tenantIdentifier be part of cache region name or stored as separate value and added as CacheBase.TenantIdentifier?
    me: keep as separate value looks more cleaner solution. Made as part of cache region to minimize overall changes
  3. Should we do something similar for QueryCache? For query cache user externally provides regionName and in this context tenantIdentifier is also available so we can leave it to user.
    me: should apply same logic

Any objections? Any other ideas how it should be implemented or suggestions?

@@ -426,25 +427,26 @@ private IQueryCache BuildQueryCache(string queryCacheName)
properties);
}

private ICacheConcurrencyStrategy GetCacheConcurrencyStrategy(
private Func<string, ICacheConcurrencyStrategy> GetCacheConcurrencyStrategy(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of cache instance returns delegate that will be used by persisters to obtain cache instance by tenantIdentifier.

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

Successfully merging this pull request may close these issues.

None yet

1 participant