public class

HashMapCache

extends AbstractCache<V, T>
implements Cache<V, T>
java.lang.Object
   ↳ org.apache.archiva.redback.components.cache.AbstractCache<V, T>
     ↳ org.apache.archiva.redback.components.cache.hashmap.HashMapCache<V, T>

Class Overview

HashMapCache - this is a Cache implementation taken from the Archiva project.

Original class written by Edwin Punzalan for purposes of addressing the jira ticket MRM-39

Configure the refreshTime in seconds value configure a ttl of object life in cache. Object get( Object key ) :

  • < 0 : method will always return null (no cache)
  • = 0 : first stored object will be return (infinite life in the cache)
  • > 0 : after a live (stored time) of refreshTime the object will be remove from the cache and a no object will be returned by the method

Summary

Public Constructors
HashMapCache()
Public Methods
void clear()
Empty the cache and reset the cache hit rate
T get(V key)
Check for a cached object and return it if it exists.
double getCacheHitRatio()
int getCacheMaxSize()
int getRefreshTime()
CacheStatistics getStatistics()
Obtain a set of Statistics about the performance of the cache.
Stats getStats()
boolean hasKey(V key)
Check if the specified key is already mapped to an object.
void initialize()
T put(V key, T value)
Cache the given value and map it using the given key
void register(V key, T value)
Cache the given value and map it using the given key
T remove(V key)
Remove the specified key and value from the cache.
void setCacheHitRatio(double cacheHitRatio)
void setCacheMaxSize(int cacheMaxSize)
void setRefreshTime(int refreshTime)
Protected Methods
boolean isCacheAvailable()
boolean needRefresh(CacheableWrapper cacheableWrapper)
[Expand]
Inherited Methods
From class org.apache.archiva.redback.components.cache.AbstractCache
From class java.lang.Object
From interface org.apache.archiva.redback.components.cache.Cache

Public Constructors

public HashMapCache ()

Public Methods

public void clear ()

Empty the cache and reset the cache hit rate

public T get (V key)

Check for a cached object and return it if it exists. Returns null when the keyed object is not found

Parameters
key the key used to map the cached object
Returns
  • the object mapped to the given key, or null if no cache object is mapped to the given key

public double getCacheHitRatio ()

public int getCacheMaxSize ()

public int getRefreshTime ()

public CacheStatistics getStatistics ()

Obtain a set of Statistics about the performance of the cache.

Returns
  • the cache statistics.

public Stats getStats ()

public boolean hasKey (V key)

Check if the specified key is already mapped to an object.

Parameters
key the key used to map the cached object
Returns
  • true if the cache contains an object associated with the given key

public void initialize ()

public T put (V key, T value)

Cache the given value and map it using the given key

Parameters
key the object to map the valued object
value the object to cache
Returns
  • the previous value for the key, or null if the key contained no value.

public void register (V key, T value)

Cache the given value and map it using the given key

Parameters
key the object to map the valued object
value the object to cache

public T remove (V key)

Remove the specified key and value from the cache.

Parameters
key the key to the value to remove.
Returns
  • the value of the key that was removed.

public void setCacheHitRatio (double cacheHitRatio)

public void setCacheMaxSize (int cacheMaxSize)

public void setRefreshTime (int refreshTime)

Protected Methods

protected boolean isCacheAvailable ()

protected boolean needRefresh (CacheableWrapper cacheableWrapper)