EhCache
From Null-pointer
Contents |
Maven
<dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache</artifactId> <version>2.0.1</version> <type>pom</type> </dependency> <!-- spring annotations --> <dependency> <groupId>com.googlecode.ehcache-spring-annotations</groupId> <artifactId>ehcache-spring-annotations</artifactId> <version>1.1.2</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>3.0.3.RELEASE</version> </dependency>
@Cachable
@Cacheable(cacheName = "applicationCache") public Application getApplication(String certSubject) { return this.applicationDAO.getApplication(certSubject); }
@TriggersRemove
@TriggersRemove(cacheName = {"userGroupRolesCache", "applicationCache"}, removeAll = true) public void deleteApplication(int appId) { }
applicationContext-ehcache.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd" > <ehcache:annotation-driven cache-manager="ehCacheManager"/> <bean id="ehCacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"> <property name="configLocation"> <value>classpath:ehcache.xml</value> </property> </bean> </beans>
ehcache.xml
<?xml version="1.0" encoding="UTF-8"?> <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" updateCheck="false"> <!-- | Please see http://ehcache.sourceforge.net/documentation/configuration.html for | detailed information on how to configure caches in this file +--> <diskStore path="java.io.tmpdir"/> <defaultCache eternal="false" maxElementsInMemory="1000" overflowToDisk="false" diskPersistent="false" timeToIdleSeconds="120" timeToLiveSeconds="600" memoryStoreEvictionPolicy="LRU"/> <!-- Application cache. Cannot change applications via ACE phase 2 1hr idle, 8hr total. --> <cache name="applicationCache" eternal="false" maxElementsInMemory="100" overflowToDisk="false" diskPersistent="false" timeToIdleSeconds="3600" timeToLiveSeconds="28800" memoryStoreEvictionPolicy="LRU" /> <!-- Users groups and roles. 2min idle, 5min total --> <cache name="userGroupRolesCache" eternal="false" maxElementsInMemory="1000" overflowToDisk="false" diskPersistent="false" timeToIdleSeconds="120" timeToLiveSeconds="300" memoryStoreEvictionPolicy="LRU" /> </ehcache>
References

