org.hibernate.cache
Class EhCache

java.lang.Object
  extended by org.hibernate.cache.EhCache
All Implemented Interfaces:
Cache

public class EhCache
extends Object
implements Cache

EHCache plugin for Hibernate

EHCache uses a net.sf.ehcache.store.MemoryStore and a net.sf.ehcache.store.DiskStore. The net.sf.ehcache.store.DiskStore requires that both keys and values be Serializable. However the MemoryStore does not and in ehcache-1.2 nonSerializable Objects are permitted. They are discarded if an attempt it made to overflow them to Disk or to replicate them to remote cache peers.

Author:
Greg Luck, Emmanuel Bernard

Constructor Summary
EhCache(net.sf.ehcache.Ehcache cache)
          Creates a new Hibernate pluggable cache based on a cache name.
 
Method Summary
 void clear()
          Remove all elements in the cache, but leave the cache in a useable state.
 void destroy()
          Remove the cache and make it unuseable.
 Object get(Object key)
          Gets a value of an element which matches the given key.
 long getElementCountInMemory()
          The count of entries currently contained in the regions in-memory store.
 long getElementCountOnDisk()
          The count of entries currently contained in the regions disk store.
 String getRegionName()
          Get the name of the cache region
 long getSizeInMemory()
          Warning: This method can be very expensive to run.
 int getTimeout()
          Returns the lock timeout for this cache.
 void lock(Object key)
          Calls to this method should perform there own synchronization.
 long nextTimestamp()
          Gets the next timestamp;
 void put(Object key, Object value)
          Puts an object into the cache.
 Object read(Object key)
          Get an item from the cache
 void remove(Object key)
          Removes the element which matches the key.
 Map toMap()
          optional operation
 String toString()
           
 void unlock(Object key)
          Calls to this method should perform there own synchronization.
 void update(Object key, Object value)
          Puts an object into the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EhCache

public EhCache(net.sf.ehcache.Ehcache cache)
Creates a new Hibernate pluggable cache based on a cache name.

Parameters:
cache - The underlying EhCache instance to use.
Method Detail

get

public Object get(Object key)
           throws CacheException
Gets a value of an element which matches the given 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
Throws:
CacheException

read

public Object read(Object key)
            throws CacheException
Description copied from interface: Cache
Get an item from the cache

Specified by:
read in interface Cache
Returns:
the cached object or null
Throws:
CacheException

update

public void update(Object key,
                   Object value)
            throws CacheException
Puts an object into the cache.

Specified by:
update in interface Cache
Parameters:
key - a key
value - a value
Throws:
CacheException - if the CacheManager is shutdown or another Exception occurs.

put

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

Specified by:
put in interface Cache
Parameters:
key - a key
value - a value
Throws:
CacheException - if the CacheManager is shutdown or another Exception occurs.

remove

public void remove(Object key)
            throws CacheException
Removes the element which matches the key.

If no element matches, nothing is removed and no Exception is thrown.

Specified by:
remove in interface Cache
Parameters:
key - the key of the element to remove
Throws:
CacheException

clear

public void clear()
           throws CacheException
Remove all elements in the cache, but leave the cache in a useable state.

Specified by:
clear in interface Cache
Throws:
CacheException

destroy

public void destroy()
             throws CacheException
Remove the cache and make it unuseable.

Specified by:
destroy in interface Cache
Throws:
CacheException

lock

public void lock(Object key)
          throws CacheException
Calls to this method should perform there own synchronization. It is provided for distributed caches. Because EHCache is not distributed this method does nothing.

Specified by:
lock in interface Cache
Throws:
CacheException

unlock

public void unlock(Object key)
            throws CacheException
Calls to this method should perform there own synchronization. It is provided for distributed caches. Because EHCache is not distributed this method does nothing.

Specified by:
unlock in interface Cache
Throws:
CacheException

nextTimestamp

public long nextTimestamp()
Gets the next timestamp;

Specified by:
nextTimestamp in interface Cache

getTimeout

public int getTimeout()
Returns the lock timeout for this cache.

Specified by:
getTimeout in interface Cache

getRegionName

public String getRegionName()
Description copied from interface: Cache
Get the name of the cache region

Specified by:
getRegionName in interface Cache

getSizeInMemory

public long getSizeInMemory()
Warning: This method can be very expensive to run. Allow approximately 1 second per 1MB of entries. Running this method could create liveness problems because the object lock is held for a long period

Specified by:
getSizeInMemory in interface Cache
Returns:
the approximate size of memory ehcache is using for the MemoryStore for this cache

getElementCountInMemory

public long getElementCountInMemory()
Description copied from interface: Cache
The count of entries currently contained in the regions in-memory store.

Specified by:
getElementCountInMemory in interface Cache
Returns:
The count of entries in memory; -1 if unknown or unsupported.

getElementCountOnDisk

public long getElementCountOnDisk()
Description copied from interface: Cache
The count of entries currently contained in the regions disk store.

Specified by:
getElementCountOnDisk in interface Cache
Returns:
The count of entries on disk; -1 if unknown or unsupported.

toMap

public Map toMap()
Description copied from interface: Cache
optional operation

Specified by:
toMap in interface Cache

toString

public String toString()
Overrides:
toString in class Object


Copyright © null-null Red Hat Middleware, LLC. All Rights Reserved