Top Description Fields Constructors Methods
net.sf.ehcache.hibernate

public final Class EhCache

extends Object
implements Cache
Class Inheritance
All Implemented Interfaces
org.hibernate.cache.Cache
Annotations
@Deprecated
Imports
net.sf.ehcache.Element, net.sf.ehcache.concurrent.CacheLockProvider, .LockType, net.sf.ehcache.util.Timestamper, org.hibernate.cache.Cache, .CacheException, java.util.HashMap, .Map, org.slf4j.Logger, .LoggerFactory

Deprecated

EHCache plugin for Hibernate.

EHCache uses a net.sf.ehcache.store.MemoryStore and a net.sf.ehcache.store.disk.DiskStore.

The net.sf.ehcache.store.disk.DiskStore requires that both keys and values be java.io.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.

Authors
Greg Luck, Emmanuel Bernard
Version
$Id: EhCache.java 10789 2018-04-26 02:08:13Z adahanne $

Field Summary

Modifier and TypeField and Description
private final Ehcache
private final CacheLockProvider
private static final Logger
private static final int

Constructor Summary

AccessConstructor and Description
public
EhCache(Ehcache
The backing ehcache cache.
cache
)

Creates a new Hibernate pluggable cache by name.

Method Summary

Modifier and TypeMethod and Description
public final boolean

Returns:

true if this cache supports entry locks.
canLockEntries
()

public final void
clear()

Implements org.hibernate.cache.Cache.clear.

Remove all elements in the cache, but leave the cache in a useable state.
public final void
destroy()

Implements org.hibernate.cache.Cache.destroy.

Remove the cache and make it unuseable.
public final Object

Returns:

The value placed into the cache with an earlier put, or null if not found or expired
get
(Object
the key of the element to return.
key
)

Implements org.hibernate.cache.Cache.get.

Gets a value of an element which matches the given key.
pack-priv final Ehcache
getBackingCache()

Package protected method used for testing

public final long

Returns:

the number of elements in ehcache's MemoryStore
getElementCountInMemory
()

Implements org.hibernate.cache.Cache.getElementCountInMemory.

The count of entries currently contained in the regions in-memory store.
public final long

Returns:

the number of elements in ehcache's DiskStore. 0 is there is no DiskStore
getElementCountOnDisk
()

Implements org.hibernate.cache.Cache.getElementCountOnDisk.

The count of entries currently contained in the regions disk store.
public final String

Returns:

the region name of the cache, which is the cache name in ehcache
getRegionName
()

Implements org.hibernate.cache.Cache.getRegionName.

Get the name of the cache region
public final long

Returns:

the approximate size of memory ehcache is using for the MemoryStore for this cache
getSizeInMemory
()

Implements org.hibernate.cache.Cache.getSizeInMemory.

Warning

This method can be very expensive to run.

public final int
getTimeout()

Implements org.hibernate.cache.Cache.getTimeout.

Returns the lock timeout for this cache, which is 60s
public final void
lock(Object key)

Implements org.hibernate.cache.Cache.lock.

If this is a clustered cache, lock the item
public final long
nextTimestamp()

Implements org.hibernate.cache.Cache.nextTimestamp.

Gets the next timestamp;
public final void
put(Object
an Object key
key
,
Object
an Object value
value
)

Implements org.hibernate.cache.Cache.put.

Puts an object into the cache.
public final Object

Returns:

the Object, or null if not found
read
(Object
an Object value
key
)

Implements org.hibernate.cache.Cache.read.

Gets an object from the cache.
public final void
remove(Object
the key of the element to remove
key
)

Implements org.hibernate.cache.Cache.remove.

Removes the element which matches the key.
public final Map<K, V>

Returns:

a copy of the cache Elements as a Map
toMap
()

Implements org.hibernate.cache.Cache.toMap.

optional operation
public final String

Returns:

the region name, which is the cache name in ehcache
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public final void
unlock(Object key)

Implements org.hibernate.cache.Cache.unlock.

If this is a clustered cache, unlock the item
public final void
update(Object
an Object key
key
,
Object
an Object value
value
)

Implements org.hibernate.cache.Cache.update.

Updates an object in the cache, or if it does not exist, inserts it.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

cacheback to summary
private final Ehcache cache
lockProviderback to summary
private final CacheLockProvider lockProvider
LOGback to summary
private static final Logger LOG
SIXTY_THOUSAND_MSback to summary
private static final int SIXTY_THOUSAND_MS

Constructor Detail

EhCacheback to summary
public EhCache(Ehcache cache)

Creates a new Hibernate pluggable cache by name.

ehcache will look in ehcache.xml to load the configuration for the cache. If the cache is not there, it will use the defaultCache settings. It is always a good idea to specifically configure each cache.

Parameters
cache:Ehcache

The backing ehcache cache.

Method Detail

canLockEntriesback to summary
public final boolean canLockEntries()
Returns:boolean

true if this cache supports entry locks.

clearback to summary
public final void clear() throws CacheException

Implements org.hibernate.cache.Cache.clear.

Remove all elements in the cache, but leave the cache in a useable state.

destroyback to summary
public final void destroy() throws CacheException

Implements org.hibernate.cache.Cache.destroy.

Remove the cache and make it unuseable.

getback to summary
public final Object get(Object key) throws CacheException

Implements org.hibernate.cache.Cache.get.

Gets a value of an element which matches the given key.

Parameters
key:Object

the key of the element to return.

Returns:Object

The value placed into the cache with an earlier put, or null if not found or expired

getBackingCacheback to summary
pack-priv final Ehcache getBackingCache()

Package protected method used for testing

getElementCountInMemoryback to summary
public final long getElementCountInMemory()

Implements org.hibernate.cache.Cache.getElementCountInMemory.

Doc from org.hibernate.cache.Cache.getElementCountInMemory.

The count of entries currently contained in the regions in-memory store.

Returns:long

the number of elements in ehcache's MemoryStore

getElementCountOnDiskback to summary
public final long getElementCountOnDisk()

Implements org.hibernate.cache.Cache.getElementCountOnDisk.

Doc from org.hibernate.cache.Cache.getElementCountOnDisk.

The count of entries currently contained in the regions disk store.

Returns:long

the number of elements in ehcache's DiskStore. 0 is there is no DiskStore

getRegionNameback to summary
public final String getRegionName()

Implements org.hibernate.cache.Cache.getRegionName.

Doc from org.hibernate.cache.Cache.getRegionName.

Get the name of the cache region

Returns:String

the region name of the cache, which is the cache name in ehcache

getSizeInMemoryback to summary
public final long getSizeInMemory()

Implements org.hibernate.cache.Cache.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

Returns:long

the approximate size of memory ehcache is using for the MemoryStore for this cache

getTimeoutback to summary
public final int getTimeout()

Implements org.hibernate.cache.Cache.getTimeout.

Returns the lock timeout for this cache, which is 60s

lockback to summary
public final void lock(Object key) throws CacheException

Implements org.hibernate.cache.Cache.lock.

Doc from org.hibernate.cache.Cache.lock.

If this is a clustered cache, lock the item

nextTimestampback to summary
public final long nextTimestamp()

Implements org.hibernate.cache.Cache.nextTimestamp.

Gets the next timestamp;

putback to summary
public final void put(Object key, Object value) throws CacheException

Implements org.hibernate.cache.Cache.put.

Puts an object into the cache.

Parameters
key:Object

an Object key

value:Object

an Object value

Exceptions
CacheException:
if the net.sf.ehcache.CacheManager is shutdown or another Exception occurs.
readback to summary
public final Object read(Object key) throws CacheException

Implements org.hibernate.cache.Cache.read.

Gets an object from the cache.

Parameters
key:Object

an Object value

Returns:Object

the Object, or null if not found

removeback to summary
public final void remove(Object key) throws CacheException

Implements org.hibernate.cache.Cache.remove.

Removes the element which matches the key.

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

Parameters
key:Object

the key of the element to remove

toMapback to summary
public final Map<K, V> toMap()

Implements org.hibernate.cache.Cache.toMap.

Doc from org.hibernate.cache.Cache.toMap.

optional operation

Returns:Map<K, V>

a copy of the cache Elements as a Map

toStringback to summary
public final String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

the region name, which is the cache name in ehcache

Annotations
@Override
unlockback to summary
public final void unlock(Object key) throws CacheException

Implements org.hibernate.cache.Cache.unlock.

Doc from org.hibernate.cache.Cache.unlock.

If this is a clustered cache, unlock the item

updateback to summary
public final void update(Object key, Object value) throws CacheException

Implements org.hibernate.cache.Cache.update.

Updates an object in the cache, or if it does not exist, inserts it.

Parameters
key:Object

an Object key

value:Object

an Object value

Exceptions
CacheException:
if the net.sf.ehcache.CacheManager is shutdown or another Exception occurs.