ehcache 2.6.3
git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-components/trunk@1447465 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/spring-cache-providers/spring-cache-ehcache/pom.xml b/spring-cache-providers/spring-cache-ehcache/pom.xml
index 8ed0660..00beb57 100644
--- a/spring-cache-providers/spring-cache-ehcache/pom.xml
+++ b/spring-cache-providers/spring-cache-ehcache/pom.xml
@@ -46,7 +46,7 @@
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
- <version>2.5.7</version>
+ <version>2.6.3</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
diff --git a/spring-cache-providers/spring-cache-ehcache/src/main/java/org/apache/archiva/redback/components/cache/ehcache/EhcacheCache.java b/spring-cache-providers/spring-cache-ehcache/src/main/java/org/apache/archiva/redback/components/cache/ehcache/EhcacheCache.java
index 2ec8d18..cffa1df 100644
--- a/spring-cache-providers/spring-cache-ehcache/src/main/java/org/apache/archiva/redback/components/cache/ehcache/EhcacheCache.java
+++ b/spring-cache-providers/spring-cache-ehcache/src/main/java/org/apache/archiva/redback/components/cache/ehcache/EhcacheCache.java
@@ -24,6 +24,9 @@
import net.sf.ehcache.Element;
import net.sf.ehcache.Status;
import net.sf.ehcache.config.CacheConfiguration;
+import net.sf.ehcache.config.Configuration;
+import net.sf.ehcache.config.DiskStoreConfiguration;
+import net.sf.ehcache.config.PersistenceConfiguration;
import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
import org.apache.archiva.redback.components.cache.CacheStatistics;
import org.slf4j.Logger;
@@ -38,8 +41,8 @@
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
*/
-public class EhcacheCache<V,T>
- implements org.apache.archiva.redback.components.cache.Cache<V,T>
+public class EhcacheCache<V, T>
+ implements org.apache.archiva.redback.components.cache.Cache<V, T>
{
private Logger log = LoggerFactory.getLogger( getClass() );
@@ -161,9 +164,14 @@
*/
private int maxElementsOnDisk;
+ /**
+ * @since 2.1
+ */
+ private boolean synchronousWrites = false;
+
private boolean statisticsEnabled = true;
- private CacheManager cacheManager = CacheManager.getInstance();
+ private CacheManager cacheManager = null;//CacheManager.getInstance();
private net.sf.ehcache.Cache ehcache;
@@ -180,6 +188,25 @@
{
stats = new Stats();
+ boolean cacheManagerExists = CacheManager.getCacheManager( getName() ) != null;
+
+ if ( cacheManagerExists )
+ {
+ if ( failOnDuplicateCache )
+ {
+ throw new RuntimeException( "A previous cacheManager with name [" + getName() + "] exists." );
+ }
+ else
+ {
+ log.warn( "skip duplicate cache " + getName() );
+ cacheManager = CacheManager.getCacheManager( getName() );
+ }
+ }
+ else
+ {
+ this.cacheManager = new CacheManager( new Configuration().name( getName() ) );
+ }
+
boolean cacheExists = cacheManager.cacheExists( getName() );
if ( cacheExists )
@@ -198,12 +225,11 @@
if ( !cacheExists )
{
CacheConfiguration cacheConfiguration = new CacheConfiguration().name( getName() ).maxEntriesLocalHeap(
- getMaxElementsInMemory() ).memoryStoreEvictionPolicy( getMemoryStoreEvictionPolicy() ).overflowToDisk(
- isOverflowToDisk() ).diskStorePath( getDiskStorePath() ).eternal( isEternal() ).timeToLiveSeconds(
- getTimeToLiveSeconds() ).timeToIdleSeconds( getTimeToIdleSeconds() ).diskPersistent(
- isDiskPersistent() ).diskExpiryThreadIntervalSeconds(
+ getMaxElementsInMemory() ).memoryStoreEvictionPolicy( getMemoryStoreEvictionPolicy() ).eternal(
+ isEternal() ).timeToLiveSeconds( getTimeToLiveSeconds() ).timeToIdleSeconds(
+ getTimeToIdleSeconds() ).diskExpiryThreadIntervalSeconds(
getDiskExpiryThreadIntervalSeconds() ).overflowToOffHeap( isOverflowToOffHeap() ).maxEntriesLocalDisk(
- maxElementsOnDisk );
+ getMaxElementsOnDisk() ).overflowToDisk( isOverflowToDisk() ).diskPersistent( diskPersistent );
if ( getMaxBytesLocalHeap() > 0 )
{
@@ -374,7 +400,6 @@
}
-
public void setMaxElementsInMemory( int maxElementsInMemory )
{
this.maxElementsInMemory = maxElementsInMemory;
@@ -483,4 +508,14 @@
this.ehcache.getCacheConfiguration().maxEntriesLocalDisk( this.maxElementsOnDisk );
}
}
+
+ public boolean isSynchronousWrites()
+ {
+ return synchronousWrites;
+ }
+
+ public void setSynchronousWrites( boolean synchronousWrites )
+ {
+ this.synchronousWrites = synchronousWrites;
+ }
}