Author: olamy
Date: Thu Dec 20 20:15:01 2012
New Revision: 1424667
URL: http://svn.apache.org/viewvc?rev=1424667&view=rev
Log:
add class type for cache to prevent cast for users
Modified:
archiva/redback/redback-components/trunk/spring-cache/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/Cache.java
archiva/redback/redback-components/trunk/spring-cache/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/impl/NoCacheCache.java
archiva/redback/redback-components/trunk/spring-cache/spring-cache-providers/spring-cache-ehcache/src/main/java/org/apache/archiva/redback/components/cache/ehcache/EhcacheCache.java
archiva/redback/redback-components/trunk/spring-cache/spring-cache-providers/spring-cache-hashmap/src/main/java/org/apache/archiva/redback/components/cache/hashmap/HashMapCache.java
archiva/redback/redback-components/trunk/spring-cache/spring-cache-providers/spring-cache-oscache/src/main/java/org/apache/archiva/redback/components/cache/oscache/OsCacheCache.java
Modified:
archiva/redback/redback-components/trunk/spring-cache/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/Cache.java
URL:
http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/spring-cache/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/Cache.java?rev=1424667&r1=1424666&r2=1424667&view=diff
==============================================================================
---
archiva/redback/redback-components/trunk/spring-cache/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/Cache.java
(original)
+++
archiva/redback/redback-components/trunk/spring-cache/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/Cache.java
Thu Dec 20 20:15:01 2012
@@ -23,7 +23,6 @@ package org.apache.archiva.redback.compo
* Cache interface.
*
* @author <a href="mailto:[email protected]">Joakim Erdfelt</a>
- *
*/
public interface Cache
{
@@ -49,6 +48,16 @@ public interface Cache
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 @@ public interface Cache
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)}
Modified:
archiva/redback/redback-components/trunk/spring-cache/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/impl/NoCacheCache.java
URL:
http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/spring-cache/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/impl/NoCacheCache.java?rev=1424667&r1=1424666&r2=1424667&view=diff
==============================================================================
---
archiva/redback/redback-components/trunk/spring-cache/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/impl/NoCacheCache.java
(original)
+++
archiva/redback/redback-components/trunk/spring-cache/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/impl/NoCacheCache.java
Thu Dec 20 20:15:01 2012
@@ -29,7 +29,6 @@ import org.apache.archiva.redback.compon
* Nothing is stored, nothing is tracked, no statistics even.
*
* @author Olivier Lamy
- *
* @since 5 February, 2007
*/
public class NoCacheCache
@@ -106,4 +105,14 @@ public class NoCacheCache
{
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;
+ }
}
Modified:
archiva/redback/redback-components/trunk/spring-cache/spring-cache-providers/spring-cache-ehcache/src/main/java/org/apache/archiva/redback/components/cache/ehcache/EhcacheCache.java
URL:
http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/spring-cache/spring-cache-providers/spring-cache-ehcache/src/main/java/org/apache/archiva/redback/components/cache/ehcache/EhcacheCache.java?rev=1424667&r1=1424666&r2=1424667&view=diff
==============================================================================
---
archiva/redback/redback-components/trunk/spring-cache/spring-cache-providers/spring-cache-ehcache/src/main/java/org/apache/archiva/redback/components/cache/ehcache/EhcacheCache.java
(original)
+++
archiva/redback/redback-components/trunk/spring-cache/spring-cache-providers/spring-cache-ehcache/src/main/java/org/apache/archiva/redback/components/cache/ehcache/EhcacheCache.java
Thu Dec 20 20:15:01 2012
@@ -245,6 +245,16 @@ public class EhcacheCache
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;
Modified:
archiva/redback/redback-components/trunk/spring-cache/spring-cache-providers/spring-cache-hashmap/src/main/java/org/apache/archiva/redback/components/cache/hashmap/HashMapCache.java
URL:
http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/spring-cache/spring-cache-providers/spring-cache-hashmap/src/main/java/org/apache/archiva/redback/components/cache/hashmap/HashMapCache.java?rev=1424667&r1=1424666&r2=1424667&view=diff
==============================================================================
---
archiva/redback/redback-components/trunk/spring-cache/spring-cache-providers/spring-cache-hashmap/src/main/java/org/apache/archiva/redback/components/cache/hashmap/HashMapCache.java
(original)
+++
archiva/redback/redback-components/trunk/spring-cache/spring-cache-providers/spring-cache-hashmap/src/main/java/org/apache/archiva/redback/components/cache/hashmap/HashMapCache.java
Thu Dec 20 20:15:01 2012
@@ -55,7 +55,7 @@ import java.util.Map;
* @author Edwin Punzalan
* @author <a href="mailto:[email protected]">Joakim Erdfelt</a>
*/
-@Service ( "cache#hashmap" )
+@Service("cache#hashmap")
public class HashMapCache
implements Cache
{
@@ -160,6 +160,16 @@ public class HashMapCache
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 @@ public class HashMapCache
}
}
- /**
- * @see org.apache.archiva.redback.components.cache.Cache#getRefreshTime()
- */
+
public int getRefreshTime()
{
return refreshTime;
Modified:
archiva/redback/redback-components/trunk/spring-cache/spring-cache-providers/spring-cache-oscache/src/main/java/org/apache/archiva/redback/components/cache/oscache/OsCacheCache.java
URL:
http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/spring-cache/spring-cache-providers/spring-cache-oscache/src/main/java/org/apache/archiva/redback/components/cache/oscache/OsCacheCache.java?rev=1424667&r1=1424666&r2=1424667&view=diff
==============================================================================
---
archiva/redback/redback-components/trunk/spring-cache/spring-cache-providers/spring-cache-oscache/src/main/java/org/apache/archiva/redback/components/cache/oscache/OsCacheCache.java
(original)
+++
archiva/redback/redback-components/trunk/spring-cache/spring-cache-providers/spring-cache-oscache/src/main/java/org/apache/archiva/redback/components/cache/oscache/OsCacheCache.java
Thu Dec 20 20:15:01 2012
@@ -33,10 +33,8 @@ import java.util.Properties;
/**
* For configuration see documentation :
http://opensymphony.com/oscache/wiki/Configuration.html
- *
*
* @author @author Olivier Lamy
- *
*/
public class OsCacheCache
implements Cache
@@ -49,15 +47,14 @@ public class OsCacheCache
//---------------------------------------------
// 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 @@ public class OsCacheCache
/**
* A default one will be added to provided CacheStatistics
- *
*/
private List cacheEventListeners;
@@ -134,18 +130,18 @@ public class OsCacheCache
}
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 class OsCacheCache
}
}
+ 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 @@ public class OsCacheCache
}
/**
- * @return list values in a String separated with comma
+ * @return list values in a String separated with comma
*/
private String getCacheEventListenersAsString()
{