Disable EHCache

Is there a way to disable ehache from the outside using a properties file? CacheManager.shutdown () doesn't seem to work? In fact, we have 2 applications with the same source code. I need ehcache in one and not in the other. one where I don't need a cache is webapp! Failed to figure out how to do this?

+3
source share
3 answers

There is a system property that you can use to do this:

net.sf.ehcache.disabled=true
+6
source

I had the same problem and Alex Miller's solution helped me. I get the value from the properties file using this technique:

<!-- Enable/disable ehCache using property in config -->
<bean
    class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetObject">
        <!-- System.getProperties() -->
        <bean
            class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
            <property name="targetClass" value="java.lang.System" />
            <property name="targetMethod" value="getProperties" />
        </bean>
    </property>
    <property name="targetMethod" value="putAll" />
    <property name="arguments">
        <!-- The new Properties -->
        <util:properties>
            <prop key="net.sf.ehcache.disabled">${net.sf.ehcache.disabled:false}</prop>

        </util:properties>
    </property>
</bean>
+1
source

Check the following line

cache.getNativeCache().getCacheManager().getCacheManagerEventListenerRegistry().notifyCacheRemoved("properties");
0
source

Source: https://habr.com/ru/post/1711978/


All Articles