net.sf.ehcache.hibernate

Class SingletonEhCacheProvider

public final class SingletonEhCacheProvider extends Object implements CacheProvider

Singleton cache Provider plugin for Hibernate 3.2 and ehcache-1.2. New in this provider is support for non Serializable keys and values. This provider works as a Singleton. No matter how many Hibernate Configurations you have, only one ehcache CacheManager is used. See EhCacheProvider for a non-singleton implementation.

Ehcache-1.2 also has many other features such as cluster support and listeners, which can be used seamlessly simply by configurion in ehcache.xml.

Use hibernate.cache.provider_class=net.sf.ehcache.hibernate.SingletonEhCacheProvider in the Hibernate configuration to enable this provider for Hibernate's second level cache.

Updated for ehcache-1.2. Note this provider requires ehcache-1.2.jar. Make sure ehcache-1.1.jar or earlier is not in the classpath or it will not work.

See http://ehcache.sf.net for documentation on ehcache

Version: $Id: SingletonEhCacheProvider.java 191 2006-09-03 22:41:48Z gregluck $

Author: Greg Luck Emmanuel Bernard

Field Summary
static StringNET_SF_EHCACHE_CONFIGURATION_RESOURCE_NAME
The Hibernate system property specifying the location of the ehcache configuration file name.
Method Summary
CachebuildCache(String name, Properties properties)
Builds a Cache.
booleanisMinimalPutsEnabledByDefault()
Not sure what this is supposed to do.
longnextTimestamp()
Returns the next timestamp.
voidstart(Properties properties)
Callback to perform any necessary initialization of the underlying cache implementation during SessionFactory construction.
voidstop()
Callback to perform any necessary cleanup of the underlying cache implementation during SessionFactory.close().

Field Detail

NET_SF_EHCACHE_CONFIGURATION_RESOURCE_NAME

public static final String NET_SF_EHCACHE_CONFIGURATION_RESOURCE_NAME
The Hibernate system property specifying the location of the ehcache configuration file name.

If set to say ehcache-1.xml, ehcache-1.xml will be looked for in the root of the classpath.

Method Detail

buildCache

public final Cache buildCache(String name, Properties properties)
Builds a Cache.

Even though this method provides properties, they are not used. Properties for EHCache are specified in the ehcache.xml file. Configuration will be read from ehcache.xml for a cache declaration where the name attribute matches the name parameter in this builder.

Parameters: name the name of the cache. Must match a cache configured in ehcache.xml properties not used

Returns: a newly built cache will be built and initialised

Throws: org.hibernate.cache.CacheException inter alia, if a cache of the same name already exists

isMinimalPutsEnabledByDefault

public final boolean isMinimalPutsEnabledByDefault()
Not sure what this is supposed to do.

Returns: false to be safe

nextTimestamp

public final long nextTimestamp()
Returns the next timestamp.

start

public final void start(Properties properties)
Callback to perform any necessary initialization of the underlying cache implementation during SessionFactory construction.

Parameters: properties current configuration settings.

stop

public void stop()
Callback to perform any necessary cleanup of the underlying cache implementation during SessionFactory.close().