cache statistics can return inmemory size btw not implemented by all cache implementations
git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-components/trunk@1354528 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/AbstractCacheStatistics.java b/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/AbstractCacheStatistics.java
index 89092d5..f2d57f2 100644
--- a/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/AbstractCacheStatistics.java
+++ b/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/AbstractCacheStatistics.java
@@ -70,4 +70,11 @@
this.cacheMiss = 0;
}
+ /**
+ * @return default implementation return 0
+ */
+ public long inMemorySize()
+ {
+ return 0;
+ }
}
diff --git a/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/CacheStatistics.java b/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/CacheStatistics.java
index 73f8b19..e067c11 100644
--- a/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/CacheStatistics.java
+++ b/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/CacheStatistics.java
@@ -58,4 +58,11 @@
* Clear the statistics of the cache.
*/
void clear();
+
+ /**
+ * return the memory used by the cache in memory
+ * <b>can be not implemented by some caches implementation</b>
+ * @since 2.0
+ */
+ long inMemorySize();
}
diff --git a/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/impl/NoCacheCache.java b/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/impl/NoCacheCache.java
index 2a6d9d0..9c31490 100644
--- a/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/impl/NoCacheCache.java
+++ b/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/impl/NoCacheCache.java
@@ -63,6 +63,11 @@
{
return 0;
}
+
+ public long inMemorySize()
+ {
+ return 0;
+ }
}
private CacheStatistics stats = new NoStats();
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 8f597d5..160763f 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
@@ -31,19 +31,17 @@
import javax.annotation.PostConstruct;
/**
- * EhcacheCache
- * configuration document available <a href="http://www.ehcache.org/documentation/configuration/index">EhcacheUserGuide</a>
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * EhcacheCache
+ * configuration document available <a href="http://www.ehcache.org/documentation/configuration/index">EhcacheUserGuide</a>
*
- *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
*/
public class EhcacheCache
implements org.apache.archiva.redback.components.cache.Cache
{
-
- private Logger log = LoggerFactory.getLogger( getClass() );
-
+
+ private Logger log = LoggerFactory.getLogger( getClass() );
+
class Stats
implements CacheStatistics
{
@@ -80,23 +78,24 @@
return ehcache.getMemoryStoreSize() + ehcache.getDiskStoreSize();
}
+ public long inMemorySize()
+ {
+ return ehcache.calculateInMemorySize();
+ }
}
/**
* how often to run the disk store expiry thread. A large number of 120 seconds plus is recommended
- *
*/
private long diskExpiryThreadIntervalSeconds = 600;
/**
* Whether to persist the cache to disk between JVM restarts.
- *
*/
private boolean diskPersistent = true;
/**
* Location on disk for the ehcache store.
- *
*/
private String diskStorePath = System.getProperty( "java.io.tmpdir" ) + "/ehcache";
@@ -122,7 +121,6 @@
/**
* Flag indicating when to use the disk store.
- *
*/
private boolean overflowToDisk = false;
@@ -135,10 +133,10 @@
*
*/
private int timeToLiveSeconds = 300;
-
+
/**
*
- */
+ */
private boolean failOnDuplicateCache = false;
private boolean statisticsEnabled = true;
@@ -175,17 +173,17 @@
}
}
- if (!cacheExists)
+ if ( !cacheExists )
{
- ehcache = new Cache( getName(), getMaxElementsInMemory(), getMemoryStoreEvictionPolicy(), isOverflowToDisk(),
- getDiskStorePath(), isEternal(), getTimeToLiveSeconds(), getTimeToIdleSeconds(),
- isDiskPersistent(), getDiskExpiryThreadIntervalSeconds(), null );
-
+ ehcache =
+ new Cache( getName(), getMaxElementsInMemory(), getMemoryStoreEvictionPolicy(), isOverflowToDisk(),
+ getDiskStorePath(), isEternal(), getTimeToLiveSeconds(), getTimeToIdleSeconds(),
+ isDiskPersistent(), getDiskExpiryThreadIntervalSeconds(), null );
cacheManager.addCache( ehcache );
ehcache.setStatisticsEnabled( statisticsEnabled );
}
- }
+ }
public void dispose()
{
@@ -206,7 +204,7 @@
public Object get( Object key )
{
- if (key == null)
+ if ( key == null )
{
return null;
}
@@ -287,7 +285,7 @@
{
ehcache.put( new Element( key, value ) );
}
-
+
public Object put( Object key, Object value )
{
// Multiple steps done to satisfy Cache API requirement for Previous object return.