0

I use ehcache (not replicated or distributed) in my application and as I know it can be accessed only from the same JVM but all the applications in the same JVM (e.g. deployed in a app server) can get values from the cache. Am I right?
What I want is that only my application can get the cache and its values. Is it possible somehow? I checked the XML config file but I haven't found any configuration to control this. Or should I set something when I get the cache from CacheManager?
It is how I get the cache in code:

private static final String LOCAL_CACHE_NAME = "LOCAL_PROTNEUT_STORE";

private Cache getCache() {
    // the name of the ehcache should be able to be configured in the general config XML
    URL url = getClass().getResource("/protneut-local-ehcache.xml");
    CacheManager manager = CacheManager.create(url);

    Cache cache = manager.getCache(LOCAL_CACHE_NAME);
    return cache;
}

The config file:

<ehcache>
    <cache name="LOCAL_PROTNEUT_STORE" maxElementsInMemory="500" eternal="true" memoryStoreEvictionPolicy="LRU" />
</ehcache>

Is it possible to control the access at all?

Thanks for the help!

Regards,
V.

Viktor
  • 1,325
  • 2
  • 19
  • 41

1 Answers1

1

In general applications don't have access to each other as they are loaded with separe classpaths (you can read more about it here) so you shouldn't worry about it.

You would have to make extra effort to make simple cache manager avialable in all applications (like make it available via JNDI or put it in shared lib)

Community
  • 1
  • 1
Kris Jaklik
  • 267
  • 1
  • 9
  • Hi Hris, thanks fo the reply! As per the http://ehcache.org/documentation/2.8/integrations/tomcat the ehcache jars have to be put to the common lib of Tomcat. Would it mean that there would be the same classloader for ehcache? V. – Viktor May 10 '15 at 13:15
  • yes libs forlder is loaded by single classloader, then the classloaders that load webapps use it to locate shared classes. So in theory if ehcache contains registry of all created caches it would be possible to access a cache created by one application in other one. – Kris Jaklik May 10 '15 at 14:23
  • If you are affraid of that just deploy ehcache jars with application. And as to memory leaks... just remember to restart tomcat on redeploys :) – Kris Jaklik May 10 '15 at 14:24