org.figure8.join.services.cache
Class EhCache

java.lang.Object
  extended by org.figure8.join.services.cache.EhCache
All Implemented Interfaces:
Cache

public class EhCache
extends java.lang.Object
implements Cache

Implementation of CacheManager using EHCache provider (see http://ehcache.sourceforge.net). It encapsulates a EH Cache.

Version:
$Revision: 1.2 $
Author:
Laurent Broudoux

Constructor Summary
EhCache(java.lang.String key, net.sf.ehcache.Cache ehcache, net.sf.ehcache.CacheManager ehcacheManager)
          Create a new instance of EhCache, wrapping a EH cache object.
 
Method Summary
 void cleanUp()
          Remove all elements from this cache and the cache itself.
 void clear()
          Remove all elements from this cache but leave it in a usable state
 java.io.Serializable get(java.io.Serializable key)
          Get the value of a cache element which matches the key
 java.util.List getElements()
          Get all the elements of this cache.
 java.lang.String getKey()
          Get the key this cache is registred within CacheManager
 net.sf.ehcache.Cache getWrappedCache()
           
 void put(java.io.Serializable key, java.io.Serializable value)
          Puts an object into the cache
 void remove(java.io.Serializable key)
          Remove an object from the cache
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EhCache

public EhCache(java.lang.String key,
               net.sf.ehcache.Cache ehcache,
               net.sf.ehcache.CacheManager ehcacheManager)
Create a new instance of EhCache, wrapping a EH cache object.

Parameters:
key - The cache name
ehcache - The encapsulated EH cache
Method Detail

getWrappedCache

public net.sf.ehcache.Cache getWrappedCache()
Returns:
The encapsulated EH Cache instance

getKey

public java.lang.String getKey()
Get the key this cache is registred within CacheManager

Specified by:
getKey in interface Cache
Returns:
This cache key (ie. its name)

getElements

public java.util.List getElements()
Get all the elements of this cache. This method returns a list that do not prevent from having duplicates !

Specified by:
getElements in interface Cache
Returns:
A List of the cache elements

get

public java.io.Serializable get(java.io.Serializable key)
Get the value of a cache element which matches the key

Specified by:
get in interface Cache
Parameters:
key - The key of the element to return
Returns:
The value placed into the cache with an earlier put, or null if not found or expired

put

public void put(java.io.Serializable key,
                java.io.Serializable value)
         throws CacheException
Puts an object into the cache

Specified by:
put in interface Cache
Parameters:
key - a serializable key
value - a serializable value
Throws:
CacheException - if object cannot be put into cache

remove

public void remove(java.io.Serializable key)
            throws CacheException
Remove an object from the cache

Specified by:
remove in interface Cache
Parameters:
key - a serializable key
Throws:
CacheException - if something went wrong during removal

clear

public void clear()
           throws CacheException
Remove all elements from this cache but leave it in a usable state

Specified by:
clear in interface Cache
Throws:
CacheException - if cache cannot be cleared

cleanUp

public void cleanUp()
             throws CacheException
Remove all elements from this cache and the cache itself. It is no longer usable. CacheManager should no longer offer access to this cache until explicit cache re-creation.

Specified by:
cleanUp in interface Cache
Throws:
CacheException - if cache cannot be cleaned up


Copyright © 2005-2008 Join. All Rights Reserved.