add class type for cache to prevent cast for users
git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-components/trunk@1424667 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/Cache.java b/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/Cache.java
index 0a9b8f8..69b6201 100644
--- a/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/Cache.java
+++ b/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/Cache.java
@@ -23,7 +23,6 @@
* Cache interface.
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- *
*/
public interface Cache
{
@@ -49,6 +48,16 @@
Object get( Object key );
/**
+ * Get the value of the specified key, if it exists in the cache.
+ *
+ * @param key the key to fetch the contents of.
+ * @param clazz class of object type to retrieve
+ * @since 2.1
+ * @return the value of the key, or null if not found.
+ */
+ <T> T get( Object key, Class<T> clazz );
+
+ /**
* Put the specified value into the cache under the provided key.
*
* @param key the key to put the value into
@@ -58,6 +67,16 @@
Object put( Object key, Object value );
/**
+ * Put the specified value into the cache under the provided key.
+ *
+ * @param key the key to put the value into
+ * @param value the object to place into the cache.
+ * @param clazz class of object type to retrieve
+ * @return the previous value for the key, or null if the key contained no value.
+ */
+ <T> T put( Object key, Object value, Class<T> clazz );
+
+ /**
* Register the specified value into the cache under the provided key.
* <p/>
* This {@link #register(Object, Object)} method is just an optimized version of the {@link #put(Object, Object)}
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 061230c..c6fd36e 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
@@ -29,7 +29,6 @@
* Nothing is stored, nothing is tracked, no statistics even.
*
* @author Olivier Lamy
- *
* @since 5 February, 2007
*/
public class NoCacheCache
@@ -106,4 +105,14 @@
{
return null;
}
+
+ public <T> T get( Object key, Class<T> clazz )
+ {
+ return null;
+ }
+
+ public <T> T put( Object key, Object value, Class<T> clazz )
+ {
+ return null;
+ }
}
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 513389c..4ff5708 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
@@ -245,6 +245,16 @@
return elem.getObjectValue();
}
+ public <T> T get( Object key, Class<T> clazz )
+ {
+ return (T) get( key );
+ }
+
+ public <T> T put( Object key, Object value, Class<T> clazz )
+ {
+ return (T) put( key, value );
+ }
+
public long getDiskExpiryThreadIntervalSeconds()
{
return diskExpiryThreadIntervalSeconds;
diff --git a/spring-cache-providers/spring-cache-hashmap/src/main/java/org/apache/archiva/redback/components/cache/hashmap/HashMapCache.java b/spring-cache-providers/spring-cache-hashmap/src/main/java/org/apache/archiva/redback/components/cache/hashmap/HashMapCache.java
index 4c1a141..b5994d0 100644
--- a/spring-cache-providers/spring-cache-hashmap/src/main/java/org/apache/archiva/redback/components/cache/hashmap/HashMapCache.java
+++ b/spring-cache-providers/spring-cache-hashmap/src/main/java/org/apache/archiva/redback/components/cache/hashmap/HashMapCache.java
@@ -55,7 +55,7 @@
* @author Edwin Punzalan
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
*/
-@Service ( "cache#hashmap" )
+@Service("cache#hashmap")
public class HashMapCache
implements Cache
{
@@ -160,6 +160,16 @@
return retValue == null ? null : retValue.getValue();
}
+ public <T> T get( Object key, Class<T> clazz )
+ {
+ return (T) get( key );
+ }
+
+ public <T> T put( Object key, Object value, Class<T> clazz )
+ {
+ return (T) put( key, value );
+ }
+
protected boolean needRefresh( CacheableWrapper cacheableWrapper )
{
if ( cacheableWrapper == null )
@@ -326,9 +336,7 @@
}
}
- /**
- * @see org.apache.archiva.redback.components.cache.Cache#getRefreshTime()
- */
+
public int getRefreshTime()
{
return refreshTime;
diff --git a/spring-cache-providers/spring-cache-oscache/src/main/java/org/apache/archiva/redback/components/cache/oscache/OsCacheCache.java b/spring-cache-providers/spring-cache-oscache/src/main/java/org/apache/archiva/redback/components/cache/oscache/OsCacheCache.java
index 56209ce..dc42378 100644
--- a/spring-cache-providers/spring-cache-oscache/src/main/java/org/apache/archiva/redback/components/cache/oscache/OsCacheCache.java
+++ b/spring-cache-providers/spring-cache-oscache/src/main/java/org/apache/archiva/redback/components/cache/oscache/OsCacheCache.java
@@ -33,10 +33,8 @@
/**
* For configuration see documentation : http://opensymphony.com/oscache/wiki/Configuration.html
- *
*
* @author @author Olivier Lamy
- *
*/
public class OsCacheCache
implements Cache
@@ -49,15 +47,14 @@
//---------------------------------------------
// Configuration attributes
//---------------------------------------------
+
/**
* use memory cache
- *
*/
private boolean cacheMemory = true;
/**
* maximum item numbers default value -1 means unlimited
- *
*/
private int capacity = -1;
@@ -93,7 +90,6 @@
/**
* A default one will be added to provided CacheStatistics
- *
*/
private List cacheEventListeners;
@@ -134,18 +130,18 @@
}
cacheProperties.put( GeneralCacheAdministrator.CACHE_BLOCKING_KEY, Boolean.toString( this.isBlockingCache() ) );
cacheProperties.put( GeneralCacheAdministrator.CACHE_CAPACITY_KEY, Integer.toString( this.getCapacity() ) );
- cacheProperties.put( GeneralCacheAdministrator.CACHE_DISK_UNLIMITED_KEY, Boolean.toString( this
- .isCacheUnlimitedDisk() ) );
+ cacheProperties.put( GeneralCacheAdministrator.CACHE_DISK_UNLIMITED_KEY,
+ Boolean.toString( this.isCacheUnlimitedDisk() ) );
String cacheEventListenersAsString = this.getCacheEventListenersAsString();
if ( cacheEventListenersAsString != null )
{
- cacheProperties
- .put( GeneralCacheAdministrator.CACHE_ENTRY_EVENT_LISTENERS_KEY, cacheEventListenersAsString );
+ cacheProperties.put( GeneralCacheAdministrator.CACHE_ENTRY_EVENT_LISTENERS_KEY,
+ cacheEventListenersAsString );
}
cacheProperties.put( GeneralCacheAdministrator.CACHE_MEMORY_KEY, Boolean.toString( this.isCacheMemory() ) );
- cacheProperties.put( GeneralCacheAdministrator.CACHE_PERSISTENCE_OVERFLOW_KEY, Boolean.toString( this
- .isCachePersistenceOverflowOnly() ) );
+ cacheProperties.put( GeneralCacheAdministrator.CACHE_PERSISTENCE_OVERFLOW_KEY,
+ Boolean.toString( this.isCachePersistenceOverflowOnly() ) );
if ( this.getCachePersistenceClass() != null )
{
@@ -206,6 +202,16 @@
}
}
+ public <T> T get( Object key, Class<T> clazz )
+ {
+ return (T) get( key );
+ }
+
+ public <T> T put( Object key, Object value, Class<T> clazz )
+ {
+ return (T) put( key, value );
+ }
+
public CacheStatistics getStatistics()
{
// osCacheStatistics to update ??
@@ -295,7 +301,7 @@
}
/**
- * @return list values in a String separated with comma
+ * @return list values in a String separated with comma
*/
private String getCacheEventListenersAsString()
{