Skip to content

FEATURE: Tenant partitioned caches could improve cache-hit ratio#2956

Closed
rPraml wants to merge 1 commit into
ebean-orm:masterfrom
FOCONIS:tenant-partitioned-caches
Closed

FEATURE: Tenant partitioned caches could improve cache-hit ratio#2956
rPraml wants to merge 1 commit into
ebean-orm:masterfrom
FOCONIS:tenant-partitioned-caches

Conversation

@rPraml

@rPraml rPraml commented Feb 2, 2023

Copy link
Copy Markdown
Contributor

Hello @rbygrave,

this is more or less a proof-of-concept, where I need your feedback

we have a multi-tenant application with ~ 50 tenants. I noticed, that we get a lot of 'cache clears' from other customers.
We cache a lot of things in our applications (user-directory, settings, ...) and if one customer updates the settings e.g. it will invalidate the caches for all other. So I tried to experimet with tenant partitioned caches, which means, each tenant has its own set of caches.

On the other hand, caches had to be created dynamically and would - at least in current implementation - stay there forever, also if the tenant does not longer exist.

I don't have exact numbers about this improvement, but do you think, this could be useful?

@rPraml rPraml changed the title Tenant partitioned caches could improve cache-hit ratio FEATURE: Tenant partitioned caches could improve cache-hit ratio Aug 8, 2023
rPraml added a commit to FOCONIS/ebean that referenced this pull request Aug 10, 2023
@rbygrave

rbygrave commented Jul 1, 2026

Copy link
Copy Markdown
Member

Updated into and replaced by #3809

@rbygrave rbygrave closed this Jul 1, 2026
rbygrave added a commit that referenced this pull request Jul 1, 2026
* Add tenant-partitioned L2 caches (#2956)

 When `tenantPartitionedCache` is enabled, each tenant gets its own
 cache namespace (keys include the tenant id), improving cache-hit
 ratio by preventing cross-tenant key collisions.

 Refactor BeanDescriptorCacheHelp to abstract base class with two
 concrete subclasses:
 - BeanDescriptorCacheHelpFixed - static cache refs (original behaviour)
 - BeanDescriptorCacheHelpPartitioned - per-request Supplier<> lookup
   so the correct tenant-scoped cache is resolved on each access

 Fix background-thread invalidation: clear(name) in partitioned mode
 now scans all matching cache entries by key prefix rather than calling
 tenantProvider.currentId() which is null/wrong on background executor
 threads.

 Add SpiCacheManager.clearTenant(tenantId) to allow removal of all
 cache entries for a deactivated tenant, preventing unbounded memory
 growth in long-running multi-tenant deployments.

 Also load cache settings (cacheMaxSize, cacheMaxIdleTime, etc.) from
 application properties - these were previously missing from loadSettings().

* Fix versions in test-java16

---------

Co-authored-by: robin.bygrave <robin.bygrave@eroad.com>
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.

2 participants