Author: olamy
Date: Sat Jan 5 22:01:59 2013
New Revision: 1429391
URL: http://svn.apache.org/viewvc?rev=1429391&view=rev
Log:
generify cache service
Modified:
archiva/redback/redback-components/trunk/spring-cache/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/AbstractCache.java
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/CacheableWrapper.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/AbstractCache.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/AbstractCache.java?rev=1429391&r1=1429390&r2=1429391&view=diff
==============================================================================
---
archiva/redback/redback-components/trunk/spring-cache/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/AbstractCache.java
(original)
+++
archiva/redback/redback-components/trunk/spring-cache/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/AbstractCache.java
Sat Jan 5 22:01:59 2013
@@ -22,8 +22,8 @@ package org.apache.archiva.redback.compo
* @author Olivier Lamy
* @since 2.1
*/
-public abstract class AbstractCache
- implements Cache
+public abstract class AbstractCache<V,T>
+ implements Cache<V,T>
{
private int timeToIdleSeconds = 0;
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=1429391&r1=1429390&r2=1429391&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
Sat Jan 5 22:01:59 2013
@@ -24,7 +24,7 @@ package org.apache.archiva.redback.compo
*
* @author <a href="mailto:[email protected]">Joakim Erdfelt</a>
*/
-public interface Cache
+public interface Cache<V,T>
{
/**
* Tests to see if the provided key exists within the cache.
@@ -37,7 +37,7 @@ public interface Cache
* @param key the key to test.
* @return true if the key exists.
*/
- boolean hasKey( Object key );
+ boolean hasKey( V key );
/**
* Get the value of the specified key, if it exists in the cache.
@@ -45,36 +45,20 @@ public interface Cache
* @param key the key to fetch the contents of.
* @return the value of the key, or null if not found.
*/
- Object get( Object key );
+ T get( V 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
- * @return the value of the key, or null if not found.
- * @since 2.1
- */
- <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
- * @param value the object to place into the cache.
- * @return the previous value for the key, or null if the key contained no
value.
- */
- 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 );
+ T put( V key, T value );
+
+
/**
* Register the specified value into the cache under the provided key.
@@ -85,7 +69,7 @@ public interface Cache
* @param key the key to put the value into
* @param value the object to place into the cache.
*/
- void register( Object key, Object value );
+ void register( V key, T value );
/**
* Remove the specified key and value from the cache.
@@ -93,7 +77,7 @@ public interface Cache
* @param key the key to the value to remove.
* @return the value of the key that was removed.
*/
- Object remove( Object key );
+ T remove( V key );
/**
* Clear the cache of all entries.
Modified:
archiva/redback/redback-components/trunk/spring-cache/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/CacheableWrapper.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/CacheableWrapper.java?rev=1429391&r1=1429390&r2=1429391&view=diff
==============================================================================
---
archiva/redback/redback-components/trunk/spring-cache/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/CacheableWrapper.java
(original)
+++
archiva/redback/redback-components/trunk/spring-cache/spring-cache-api/src/main/java/org/apache/archiva/redback/components/cache/CacheableWrapper.java
Sat Jan 5 22:01:59 2013
@@ -27,25 +27,25 @@ import java.io.Serializable;
* @author Olivier Lamy
*
*/
-public class CacheableWrapper
+public class CacheableWrapper<T>
implements Serializable
{
- private Object value;
+ private T value;
private long storedTime;
- public CacheableWrapper( Object value, long storedTime )
+ public CacheableWrapper( T value, long storedTime )
{
this.value = value;
this.storedTime = storedTime;
}
- public Object getValue()
+ public T getValue()
{
return value;
}
- public void setValue( Object value )
+ public void setValue( T value )
{
this.value = value;
}
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=1429391&r1=1429390&r2=1429391&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
Sat Jan 5 22:01:59 2013
@@ -32,9 +32,9 @@ import org.apache.archiva.redback.compon
* @author Olivier Lamy
* @since 5 February, 2007
*/
-public class NoCacheCache
- extends AbstractCache
- implements Cache
+public class NoCacheCache<V, T>
+ extends AbstractCache<V, T>
+ implements Cache<V, T>
{
static final class NoStats
implements CacheStatistics
@@ -78,7 +78,7 @@ public class NoCacheCache
/* do nothing */
}
- public Object get( Object key )
+ public T get( V key )
{
return null;
}
@@ -88,32 +88,22 @@ public class NoCacheCache
return stats;
}
- public boolean hasKey( Object key )
+ public boolean hasKey( V key )
{
return false;
}
- public Object put( Object key, Object value )
+ public T put( V key, T value )
{
return null;
}
- public void register( Object key, Object value )
+ public void register( V key, T value )
{
/* do nothing */
}
- public Object remove( Object key )
- {
- return null;
- }
-
- public <T> T get( Object key, Class<T> clazz )
- {
- return null;
- }
-
- public <T> T put( Object key, Object value, Class<T> clazz )
+ public T remove( V key )
{
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=1429391&r1=1429390&r2=1429391&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
Sat Jan 5 22:01:59 2013
@@ -38,8 +38,8 @@ import javax.annotation.PreDestroy;
*
* @author <a href="mailto:[email protected]">Joakim Erdfelt</a>
*/
-public class EhcacheCache
- implements org.apache.archiva.redback.components.cache.Cache
+public class EhcacheCache<V,T>
+ implements org.apache.archiva.redback.components.cache.Cache<V,T>
{
private Logger log = LoggerFactory.getLogger( getClass() );
@@ -239,7 +239,7 @@ public class EhcacheCache
}
}
- public Object get( Object key )
+ public T get( V key )
{
if ( key == null )
{
@@ -251,17 +251,7 @@ public class EhcacheCache
{
return null;
}
- 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 );
+ return (T) elem.getObjectValue();
}
public long getDiskExpiryThreadIntervalSeconds()
@@ -309,7 +299,7 @@ public class EhcacheCache
return timeToLiveSeconds;
}
- public boolean hasKey( Object key )
+ public boolean hasKey( V key )
{
return ehcache.isKeyInCache( key );
}
@@ -329,12 +319,12 @@ public class EhcacheCache
return overflowToDisk;
}
- public void register( Object key, Object value )
+ public void register( V key, T value )
{
ehcache.put( new Element( key, value ) );
}
- public Object put( Object key, Object value )
+ public T put( V key, T value )
{
// Multiple steps done to satisfy Cache API requirement for Previous
object return.
Element elem = null;
@@ -346,10 +336,10 @@ public class EhcacheCache
}
elem = new Element( key, value );
ehcache.put( elem );
- return previous;
+ return (T) previous;
}
- public Object remove( Object key )
+ public T remove( V key )
{
Element elem = null;
Object previous = null;
@@ -360,7 +350,7 @@ public class EhcacheCache
ehcache.remove( key );
}
- return previous;
+ return (T) previous;
}
public void setDiskExpiryThreadIntervalSeconds( long
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=1429391&r1=1429390&r2=1429391&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
Sat Jan 5 22:01:59 2013
@@ -57,9 +57,9 @@ import java.util.Map;
* @author <a href="mailto:[email protected]">Joakim Erdfelt</a>
*/
@Service("cache#hashmap")
-public class HashMapCache
- extends AbstractCache
- implements Cache
+public class HashMapCache<V,T>
+ extends AbstractCache<V,T>
+ implements Cache<V,T>
{
private Logger log = LoggerFactory.getLogger( getClass() );
@@ -84,7 +84,7 @@ public class HashMapCache
}
- private Map cache;
+ private Map<V,CacheableWrapper<T>> cache;
/**
*
@@ -127,9 +127,9 @@ public class HashMapCache
* @param key the key used to map the cached object
* @return the object mapped to the given key, or null if no cache object
is mapped to the given key
*/
- public Object get( Object key )
+ public T get( V key )
{
- CacheableWrapper retValue = null;
+ CacheableWrapper<T> retValue = null;
// prevent search
if ( !this.isCacheAvailable() )
{
@@ -140,7 +140,7 @@ public class HashMapCache
if ( cache.containsKey( key ) )
{
// remove and put: this promotes it to the top since we use a
linked hash map
- retValue = (CacheableWrapper) cache.remove( key );
+ retValue = cache.remove( key );
if ( needRefresh( retValue ) )
{
@@ -162,15 +162,7 @@ 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 )
{
@@ -201,7 +193,7 @@ public class HashMapCache
* @param key the key used to map the cached object
* @return true if the cache contains an object associated with the given
key
*/
- public boolean hasKey( Object key )
+ public boolean hasKey( V key )
{
// prevent search
if ( !this.isCacheAvailable() )
@@ -233,11 +225,11 @@ public class HashMapCache
if ( cacheMaxSize > 0 )
{
- cache = new LinkedHashMap( cacheMaxSize );
+ cache = new LinkedHashMap<V,CacheableWrapper<T>>( cacheMaxSize );
}
else
{
- cache = new LinkedHashMap();
+ cache = new LinkedHashMap<V,CacheableWrapper<T>>();
}
}
@@ -247,9 +239,9 @@ public class HashMapCache
* @param key the object to map the valued object
* @param value the object to cache
*/
- public Object put( Object key, Object value )
+ public T put( V key, T value )
{
- CacheableWrapper ret = null;
+ CacheableWrapper<T> ret = null;
// remove and put: this promotes it to the top since we use a linked
hash map
synchronized ( cache )
@@ -259,7 +251,7 @@ public class HashMapCache
cache.remove( key );
}
- ret = (CacheableWrapper) cache.put( key, new CacheableWrapper(
value, System.currentTimeMillis() ) );
+ ret = cache.put( key, new CacheableWrapper<T>( value,
System.currentTimeMillis() ) );
}
manageCache();
@@ -273,7 +265,7 @@ public class HashMapCache
* @param key the object to map the valued object
* @param value the object to cache
*/
- public void register( Object key, Object value )
+ public void register( V key, T value )
{
// remove and put: this promotes it to the top since we use a linked
hash map
synchronized ( cache )
@@ -283,19 +275,19 @@ public class HashMapCache
cache.remove( key );
}
- cache.put( key, new CacheableWrapper( value,
System.currentTimeMillis() ) );
+ cache.put( key, new CacheableWrapper<T>( value,
System.currentTimeMillis() ) );
}
manageCache();
}
- public Object remove( Object key )
+ public T remove( V key )
{
synchronized ( cache )
{
if ( cache.containsKey( key ) )
{
- return cache.remove( key );
+ return cache.remove( key ).getValue();
}
}
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=1429391&r1=1429390&r2=1429391&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
Sat Jan 5 22:01:59 2013
@@ -37,9 +37,9 @@ import java.util.Properties;
*
* @author @author Olivier Lamy
*/
-public class OsCacheCache
- extends AbstractCache
- implements Cache
+public class OsCacheCache<V, T>
+ extends AbstractCache<V, T>
+ implements Cache<V, T>
{
private GeneralCacheAdministrator generalCacheAdministrator;
@@ -173,18 +173,18 @@ public class OsCacheCache
this.generalCacheAdministrator.flushAll();
}
- public Object get( Object key )
+ public T get( V key )
{
try
{
- Object object = null;
+ T object = null;
if ( this.getRefreshPeriod() >= 0 )
{
- object = this.generalCacheAdministrator.getFromCache(
key.toString(), this.getRefreshPeriod() );
+ object = (T) this.generalCacheAdministrator.getFromCache(
key.toString(), this.getRefreshPeriod() );
}
else
{
- object = this.generalCacheAdministrator.getFromCache(
key.toString() );
+ object = (T) this.generalCacheAdministrator.getFromCache(
key.toString() );
}
if ( object != null )
{
@@ -204,15 +204,6 @@ 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()
{
@@ -220,18 +211,18 @@ public class OsCacheCache
return this.osCacheStatistics;
}
- public boolean hasKey( Object key )
+ public boolean hasKey( V key )
{
// TODO if null increase/decrease statistics ?
return this.get( key ) == null;
}
- public void register( Object key, Object value )
+ public void register( V key, T value )
{
this.generalCacheAdministrator.putInCache( key.toString(), value );
}
- public Object put( Object key, Object value )
+ public T put( V key, T value )
{
Object previous = null;
try
@@ -243,10 +234,10 @@ public class OsCacheCache
// ignore this because the content will be updated
}
this.generalCacheAdministrator.putInCache( key.toString(), value );
- return previous;
+ return (T) previous;
}
- public Object remove( Object key )
+ public T remove( V key )
{
Object previous = null;
try
@@ -260,7 +251,7 @@ public class OsCacheCache
}
this.generalCacheAdministrator.cancelUpdate( key.toString() );
this.generalCacheAdministrator.flushEntry( key.toString() );
- return previous;
+ return (T) previous;
}
//---------------------------------------------