org.xwiki.cache.internal
Class DefaultCache<T>

java.lang.Object
  extended by org.xwiki.cache.internal.DefaultCache<T>
Type Parameters:
T - the class of the data stored in the cache.
All Implemented Interfaces:
Cache<T>

public class DefaultCache<T>
extends java.lang.Object
implements Cache<T>

Default implementation of Cache. Does not really store anything and always return null when trying to get a value associated with a key.

Version:
$Id$

Constructor Summary
DefaultCache()
           
 
Method Summary
 void addCacheEntryListener(CacheEntryListener<T> listener)
          Add the provided listener to the cache to catch events on entries like add, remove etc.
 void dispose()
          Release all the resources this cache use.
 T get(java.lang.String key)
          
 int getSize()
          
 void remove(java.lang.String key)
          Remove the entry associated with the provided key from the cache.
 void removeAll()
          Remove all the entries the cache contains.
 void removeCacheEntryListener(CacheEntryListener<T> listener)
          Remove the provided listener from the list of listeners.
 void set(java.lang.String key, T obj)
          Add a new value or overwrite the existing one associated with the provided key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultCache

public DefaultCache()
Method Detail

remove

public void remove(java.lang.String key)
Remove the entry associated with the provided key from the cache.

You can catch this events using CacheEntryListener.cacheEntryRemoved(org.xwiki.cache.event.CacheEntryEvent)

Specified by:
remove in interface Cache<T>
Parameters:
key - the key used to access the value in the cache.
See Also:
Cache.remove(java.lang.String)

set

public void set(java.lang.String key,
                T obj)
Add a new value or overwrite the existing one associated with the provided key. *

You can catch this events using CacheEntryListener.cacheEntryAdded(org.xwiki.cache.event.CacheEntryEvent) or CacheEntryListener.cacheEntryModified(org.xwiki.cache.event.CacheEntryEvent)

Specified by:
set in interface Cache<T>
Parameters:
key - the associated key used to access the value in the cache.
obj - the value to store in the cache.
See Also:
Cache.set(java.lang.String, java.lang.Object)

get

public T get(java.lang.String key)

Specified by:
get in interface Cache<T>
Parameters:
key - the key used to access the value in the cache.
Returns:
the value associated with the provided key, or null if there is no value.
See Also:
Cache.get(java.lang.String)

removeAll

public void removeAll()
Remove all the entries the cache contains.

Specified by:
removeAll in interface Cache<T>
See Also:
Cache.removeAll()

getSize

public int getSize()

See Also:
org.xwiki.cache.Cache#getSize()

addCacheEntryListener

public void addCacheEntryListener(CacheEntryListener<T> listener)
Add the provided listener to the cache to catch events on entries like add, remove etc.

Specified by:
addCacheEntryListener in interface Cache<T>
Parameters:
listener - the implemented listener.
See Also:
Cache.addCacheEntryListener(org.xwiki.cache.event.CacheEntryListener)

removeCacheEntryListener

public void removeCacheEntryListener(CacheEntryListener<T> listener)
Remove the provided listener from the list of listeners.

Specified by:
removeCacheEntryListener in interface Cache<T>
Parameters:
listener - the implemented listener.
See Also:
Cache.removeCacheEntryListener(org.xwiki.cache.event.CacheEntryListener)

dispose

public void dispose()
Release all the resources this cache use.

Specified by:
dispose in interface Cache<T>
See Also:
Cache.dispose()


Copyright © 2004-2011 XWiki. All Rights Reserved.