Support for multiple CacheManagers

19 views
Skip to first unread message

Aaron Anderson

unread,
May 12, 2013, 12:22:59 AM5/12/13
to jsr...@googlegroups.com
I am working on a CDI project where I would like to instantiate a CacheManager inside a custom scope. The idea is that Cache injection points annotated in the custom scope would be created with a single CacheManager in the custom scope and then when the custom scope is destroyed the CacheManager and all transient caches would be closed as well. Since my application is partitioned using custom scopes I would like to manage the Cache instances through scoped CachedManagers rather than trying to explicitly close global Cache instances when the custom scope is destroyed.


It appears the CachingProvider SPI class contains methods for obtaining new CacheManager instances but it takes an opaque vendor specific URIs. Also according to the CachingProvider JavaDocs CacheManagers are scoped by classloader but that does not easily lend itself for mapping to custom CDI scopes. Any insight on how best to support this use case?

Thanks,

Aaron

Brian Oliver

unread,
Jun 6, 2013, 9:22:33 AM6/6/13
to jsr...@googlegroups.com
Hi Aaron,

In most cases the URI provide by the CachingProvider allows for any scoping mechanism we can think of.   eg:  The URI can be used for the name of an application, or the name of a jar / war / ear, or domain of a company etc.   There's no reason why you also can't use it for CDI, in which case I'm guessing you may need to write your own CachingProvider.

Ultimately CacheManagers are scoped by the tuple of URI and ClassLoader.  Together this allows things like side-by-side deployment of applications in a container, with the same "jar" name, but with different ClassLoaders.

Hope this helps

-- Brian
Reply all
Reply to author
Forward
0 new messages