Multi Tenant Caching

863 views
Skip to first unread message

Mike Bushman

unread,
Jan 29, 2013, 6:59:04 PM1/29/13
to ehcache-sprin...@googlegroups.com
I'm using the spring annotations and all is working quite well (thanks!).  I have run into one issue.  The application is multi-tenant, but the cacheName is the @Cachable annotation must be a constant, so each tenant shares the same cache.  I've written my own CacheKeyGenerator implementation to handle the different tenants by adding a tenant_id to the end of each Key.  However, now I'm implementing the @TriggersRemove(cacheName="someCache", removeAll=true), and now I'm realizing that the cache for all tenants would be flushed.  I've implemented a workaround to iterate thru the keys and only remove the cache entry if the key ends with a certain tentant_id, but this could result in looping thru hundreds of thousands of elements in certain situations.

Is there anyway to use sub-caches per tenant, or add a dynamic portion to the cacheName where I could add the tenant_id somehow.

Any thoughts, ideas, or solutions would be thankfully welcomed.

David Karlsen

unread,
Jan 30, 2013, 3:00:13 AM1/30/13
to ehcache-sprin...@googlegroups.com
I asked for this through this issue:
http://code.google.com/p/ehcache-spring-annotations/issues/detail?id=49&can=1&q=reporter%3Adavidkarlsen

It's fixed - but I never saw any docs for how to use it - and have
left the project where I needed it.

2013/1/30 Mike Bushman <bushma...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups
> "Ehcache Spring Annotations" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ehcache-spring-anno...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
--
David J. M. Karlsen - http://www.linkedin.com/in/davidkarlsen

Eric Dalquist

unread,
Jan 30, 2013, 8:41:45 AM1/30/13
to ehcache-sprin...@googlegroups.com
What you want to look at is: @Cacheable.resolveFactory

That lets you specify a CacheResolverFactory. The CacheResolverFactory is called once per annotated method at init time to determine the CacheableCacheResolver to use at runtime. The CacheableCacheResolver is called every time an @Cacheable annotated method is invoked and returns the Ehcache instance to be used for that invocation. There is also a TriggersRemoveCacheResolver that handles @TriggersRemove annotated methods.

-Eric



--
Reply all
Reply to author
Forward
0 new messages