eXo Kernel :: Component :: Cache Service 2.4.0-CR2

org.exoplatform.services.cache.invalidation
Class InvalidationExoCache<K extends Serializable,V>

java.lang.Object
  extended by org.exoplatform.services.cache.invalidation.InvalidationExoCache<K,V>
All Implemented Interfaces:
CacheListener<K,InvalidationExoCache.HashCode<V>>, ExoCache<K,V>

public class InvalidationExoCache<K extends Serializable,V>
extends Object
implements ExoCache<K,V>, CacheListener<K,InvalidationExoCache.HashCode<V>>

This eXo cache type is a decorator allowing ExoCache instances that have big values or non serializable values to be replicated thanks to an invalidation mechanism. To prevent infinite loop described below, we replicate the hash code of the value such that if the hash code is the same, we don't invalidate the value locally

Version:
$Id$
Author:
Nicolas Filotto

Nested Class Summary
static class InvalidationExoCache.HashCode<V>
          We use this class to propagate the hash code of the value efficiently over the network
 
Constructor Summary
InvalidationExoCache(ExoCache<K,V> delegate)
           
InvalidationExoCache(ExoCache<K,V> delegate, int concurrencyLevel)
           
 
Method Summary
 void addCacheListener(CacheListener<? super K,? super V> listener)
          Add a listener.
 void clearCache()
          Clears the cache.
 V get(Serializable name)
          Performs a lookup operation.
 List<? extends V> getCachedObjects()
          Returns a list of cached object that are considered as valid when the method is called.
 int getCacheHit()
          Returns the number of time the cache was queried and a valid entry was returned.
 int getCacheMiss()
          Returns the number of time the cache was queried and no entry was returned.
 int getCacheSize()
          Returns the number of entries in the cache.
 String getLabel()
           
 long getLiveTime()
          Returns the maximum life time of an entry in the cache.
 int getMaxSize()
          Returns the maximum capacity of the cache.
 String getName()
          Returns the cache name
 boolean isLogEnabled()
           
 void onClearCache(CacheListenerContext context)
          The cache is globally cleared.
 void onExpire(CacheListenerContext context, K key, InvalidationExoCache.HashCode<V> obj)
          An entry is expired from the cache.
 void onGet(CacheListenerContext context, K key, InvalidationExoCache.HashCode<V> obj)
          An entry is retrieved from the cache.
 void onPut(CacheListenerContext context, K key, InvalidationExoCache.HashCode<V> obj)
          An entry is inserted in the cache.
 void onRemove(CacheListenerContext context, K key, InvalidationExoCache.HashCode<V> obj)
          An entry is removed from the cache.
 void put(K key, V value)
          Performs a put in the cache.
 void putMap(Map<? extends K,? extends V> objs)
          Performs a put of all the entries provided by the map argument.
 V remove(Serializable key)
          Removes an entry from the cache.
 List<? extends V> removeCachedObjects()
          Clears the cache and returns the list of cached object that are considered as valid when the method is called.
 void select(CachedObjectSelector<? super K,? super V> selector)
          Selects a subset of the cache.
 void setLabel(String s)
           
 void setLiveTime(long period)
          Sets the maximum life time of an entry in the cache.
 void setLogEnabled(boolean b)
           
 void setMaxSize(int max)
          Sets the maximum capacity of the cache.
 void setName(String name)
          Sets the cache name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InvalidationExoCache

public InvalidationExoCache(ExoCache<K,V> delegate)
Parameters:
delegate - the underneath eXo cache instance, we assume that the eXo cache implementation behind is fully functional.

InvalidationExoCache

public InvalidationExoCache(ExoCache<K,V> delegate,
                            int concurrencyLevel)
Parameters:
delegate - the underneath eXo cache instance, we assume that the eXo cache implementation behind is fully functional.
Method Detail

getName

public String getName()
Description copied from interface: ExoCache
Returns the cache name

Specified by:
getName in interface ExoCache<K extends Serializable,V>
Returns:
the cache name
See Also:
ExoCache.getName()

setName

public void setName(String name)
Description copied from interface: ExoCache
Sets the cache name.

Specified by:
setName in interface ExoCache<K extends Serializable,V>
Parameters:
name - the cache name
See Also:
ExoCache.setName(java.lang.String)

getLabel

public String getLabel()
Specified by:
getLabel in interface ExoCache<K extends Serializable,V>
See Also:
ExoCache.getLabel()

setLabel

public void setLabel(String s)
Specified by:
setLabel in interface ExoCache<K extends Serializable,V>
See Also:
ExoCache.setLabel(java.lang.String)

get

public V get(Serializable name)
Description copied from interface: ExoCache
Performs a lookup operation.

Specified by:
get in interface ExoCache<K extends Serializable,V>
Parameters:
name - the cache key
Returns:
the cached value which may be evaluated to null
See Also:
ExoCache.get(java.io.Serializable)

remove

public V remove(Serializable key)
         throws NullPointerException
Description copied from interface: ExoCache
Removes an entry from the cache.

Specified by:
remove in interface ExoCache<K extends Serializable,V>
Parameters:
key - the cache key
Returns:
the previously cached value or null if no entry existed or that entry value was evaluated to null
Throws:
NullPointerException - if the provided key is null
See Also:
ExoCache.remove(java.io.Serializable)

put

public void put(K key,
                V value)
         throws NullPointerException
Description copied from interface: ExoCache
Performs a put in the cache.

Specified by:
put in interface ExoCache<K extends Serializable,V>
Parameters:
key - the cache key
value - the cached value
Throws:
NullPointerException - if the key is null
See Also:
ExoCache.put(java.io.Serializable, java.lang.Object)

putMap

public void putMap(Map<? extends K,? extends V> objs)
            throws IllegalArgumentException
Description copied from interface: ExoCache
Performs a put of all the entries provided by the map argument.

Specified by:
putMap in interface ExoCache<K extends Serializable,V>
Parameters:
objs - the objects to put
Throws:
IllegalArgumentException - if the provided map contains a null key
See Also:
ExoCache.putMap(java.util.Map)

clearCache

public void clearCache()
Description copied from interface: ExoCache
Clears the cache.

Specified by:
clearCache in interface ExoCache<K extends Serializable,V>
See Also:
ExoCache.clearCache()

select

public void select(CachedObjectSelector<? super K,? super V> selector)
            throws Exception
Description copied from interface: ExoCache
Selects a subset of the cache.

Specified by:
select in interface ExoCache<K extends Serializable,V>
Parameters:
selector - the selector
Throws:
Exception - any exception
See Also:
ExoCache.select(org.exoplatform.services.cache.CachedObjectSelector)

getCacheSize

public int getCacheSize()
Description copied from interface: ExoCache
Returns the number of entries in the cache.

Specified by:
getCacheSize in interface ExoCache<K extends Serializable,V>
Returns:
the size of the cache
See Also:
ExoCache.getCacheSize()

getMaxSize

public int getMaxSize()
Description copied from interface: ExoCache
Returns the maximum capacity of the cache.

Specified by:
getMaxSize in interface ExoCache<K extends Serializable,V>
Returns:
the maximum capacity
See Also:
ExoCache.getMaxSize()

setMaxSize

public void setMaxSize(int max)
Description copied from interface: ExoCache
Sets the maximum capacity of the cache.

Specified by:
setMaxSize in interface ExoCache<K extends Serializable,V>
Parameters:
max - the maximum capacity
See Also:
ExoCache.setMaxSize(int)

getLiveTime

public long getLiveTime()
Description copied from interface: ExoCache
Returns the maximum life time of an entry in the cache. The life time is a value in seconds, a negative value means that the life time is infinite.

Specified by:
getLiveTime in interface ExoCache<K extends Serializable,V>
Returns:
the live time
See Also:
ExoCache.getLiveTime()

setLiveTime

public void setLiveTime(long period)
Description copied from interface: ExoCache
Sets the maximum life time of an entry in the cache.

Specified by:
setLiveTime in interface ExoCache<K extends Serializable,V>
Parameters:
period - the live time
See Also:
ExoCache.setLiveTime(long)

getCacheHit

public int getCacheHit()
Description copied from interface: ExoCache
Returns the number of time the cache was queried and a valid entry was returned.

Specified by:
getCacheHit in interface ExoCache<K extends Serializable,V>
Returns:
the cache hits
See Also:
ExoCache.getCacheHit()

getCacheMiss

public int getCacheMiss()
Description copied from interface: ExoCache
Returns the number of time the cache was queried and no entry was returned.

Specified by:
getCacheMiss in interface ExoCache<K extends Serializable,V>
Returns:
the cache misses
See Also:
ExoCache.getCacheMiss()

getCachedObjects

public List<? extends V> getCachedObjects()
Description copied from interface: ExoCache
Returns a list of cached object that are considered as valid when the method is called. Any non valid object will not be returnted.

Specified by:
getCachedObjects in interface ExoCache<K extends Serializable,V>
Returns:
the list of cached objects
See Also:
ExoCache.getCachedObjects()

removeCachedObjects

public List<? extends V> removeCachedObjects()
Description copied from interface: ExoCache
Clears the cache and returns the list of cached object that are considered as valid when the method is called. Any non valid object will not be returned.

Specified by:
removeCachedObjects in interface ExoCache<K extends Serializable,V>
Returns:
the list of cached objects
See Also:
ExoCache.removeCachedObjects()

addCacheListener

public void addCacheListener(CacheListener<? super K,? super V> listener)
                      throws IllegalArgumentException
Description copied from interface: ExoCache
Add a listener.

Specified by:
addCacheListener in interface ExoCache<K extends Serializable,V>
Parameters:
listener - the listener to add
Throws:
IllegalArgumentException
See Also:
ExoCache.addCacheListener(org.exoplatform.services.cache.CacheListener)

isLogEnabled

public boolean isLogEnabled()
Specified by:
isLogEnabled in interface ExoCache<K extends Serializable,V>
See Also:
ExoCache.isLogEnabled()

setLogEnabled

public void setLogEnabled(boolean b)
Specified by:
setLogEnabled in interface ExoCache<K extends Serializable,V>
See Also:
ExoCache.setLogEnabled(boolean)

onExpire

public void onExpire(CacheListenerContext context,
                     K key,
                     InvalidationExoCache.HashCode<V> obj)
              throws Exception
An entry is expired from the cache.

Specified by:
onExpire in interface CacheListener<K extends Serializable,InvalidationExoCache.HashCode<V>>
Parameters:
context - the listener context
key - the entry key
obj - the entry value
Throws:
Exception - any exception

onRemove

public void onRemove(CacheListenerContext context,
                     K key,
                     InvalidationExoCache.HashCode<V> obj)
              throws Exception
An entry is removed from the cache.

Specified by:
onRemove in interface CacheListener<K extends Serializable,InvalidationExoCache.HashCode<V>>
Parameters:
context - the listener context
key - the entry key
obj - the entry value
Throws:
Exception - any exception

onPut

public void onPut(CacheListenerContext context,
                  K key,
                  InvalidationExoCache.HashCode<V> obj)
           throws Exception
An entry is inserted in the cache.

Specified by:
onPut in interface CacheListener<K extends Serializable,InvalidationExoCache.HashCode<V>>
Parameters:
context - the listener context
key - the entry key
obj - the entry value
Throws:
Exception - any exception

onGet

public void onGet(CacheListenerContext context,
                  K key,
                  InvalidationExoCache.HashCode<V> obj)
           throws Exception
An entry is retrieved from the cache.

Specified by:
onGet in interface CacheListener<K extends Serializable,InvalidationExoCache.HashCode<V>>
Parameters:
context - the listener context
key - the entry key
obj - the entry value
Throws:
Exception - any exception

onClearCache

public void onClearCache(CacheListenerContext context)
                  throws Exception
Description copied from interface: CacheListener
The cache is globally cleared.

Specified by:
onClearCache in interface CacheListener<K extends Serializable,InvalidationExoCache.HashCode<V>>
Parameters:
context - the listener context
Throws:
Exception - any exception
See Also:
CacheListener.onClearCache(org.exoplatform.services.cache.CacheListenerContext)

eXo Kernel :: Component :: Cache Service 2.4.0-CR2

Copyright © 2012 eXo Platform SAS. All Rights Reserved.