WIP Multi-Tenancy: Separate second-level cache per tenant (prototype for discussion) #2133
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.
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 changeBulkOperationCleanupAction
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:
tenantIdentifier
as part ofCacheKey
?me: for now seems unnecessary.
tenantIdentifier
be part of cache region name or stored as separate value and added asCacheBase.TenantIdentifier
?me:
keep as separate value looks more cleaner solution.Made as part of cache region to minimize overall changesQueryCache
? For query cache user externally providesregionName
and in this contexttenantIdentifier
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?