com.googlecode.hibernate.memcached
Class MemcachedCacheProvider

java.lang.Object
  extended by com.googlecode.hibernate.memcached.MemcachedCacheProvider
All Implemented Interfaces:
org.hibernate.cache.CacheProvider

public class MemcachedCacheProvider
extends Object
implements org.hibernate.cache.CacheProvider

Configures an instance of MemcachedCache for use as a second-level cache in Hibernate. To use set the hibernate property hibernate.cache.provider_class to the name of this class.

There are two types of property settings that the MemcachedCacheProvider supports, cache-wide properties and region-name properties.

Cache wide properties

PropertyDefaultDescription
hibernate.memcached.serverslocalhost:11211 Space delimited list of memcached instances in host:port format
hibernate.memcached.cacheTimeSeconds300 The default number of seconds items should be cached. Can be overriden at the regon level.
hibernate.memcached.keyStrategySha1KeyStrategy Sets the strategy class to to use for generating cache keys. Must provide a class name that implements KeyStrategy
hibernate.memcached.readBufferSize DefaultConnectionFactory.DEFAULT_READ_BUFFER_SIZE The read buffer size for each server connection from this factory
hibernate.memcached.operationQueueLength DefaultConnectionFactory.DEFAULT_OP_QUEUE_LEN Maximum length of the operation queue returned by this connection factory
hibernate.memcached.operationTimeout DefaultConnectionFactory.DEFAULT_OPERATION_TIMEOUT Default operation timeout in milliseconds
hibernate.memcached.hashAlgorithmHashAlgorithm.KETAMA_HASH Which hash algorithm to use when adding items to the cache.
Note: the MemcachedClient defaults to using HashAlgorithm.NATIVE_HASH, while the hibernate-memcached cache defaults to KETAMA_HASH for "consistent hashing"
hibernate.memcached.clearSupportedfalse Enables support for the MemcachedCache.clear() method for all cache regions. The way clear is implemented for memcached is expensive and adds overhead to all get/set operations. It is not recommended for production use.

Cache Region properties
Cache regon properties are set by giving your cached data a "region name" in hibernate. You can tune the MemcachedCache instance for your region using the following properties. These properties essentially override the cache-wide properties above.

PropertyDefaultDescription
hibernate.memcached.[region-name].cacheTimeSeconds none, see hibernate.memcached.cacheTimeSeconds Set the cache time for this cache region, overriding the cache-wide setting.
hibernate.memcached.[region-name].keyStrategynone, see hibernate.memcached.keyStrategy Overrides the strategy class to to use for generating cache keys in this cache region. Must provide a class name that implements KeyStrategy
hibernate.memcached.[region-name].clearSupported none, see hibernate.memcached.clearSupported Enables clear() operations for this cache region only. Again, the clear operation incurs cost on every get/set operation.

Author:
Ray Krueger

Constructor Summary
MemcachedCacheProvider()
           
 
Method Summary
 org.hibernate.cache.Cache buildCache(String regionName, Properties properties)
           
protected  MemcacheClientFactory getMemcachedClientFactory(Config config)
           
protected  KeyStrategy instantiateKeyStrategy(String cls)
           
 boolean isMinimalPutsEnabledByDefault()
          According to the hibernate reference docs, MinimalPutsEnabledByDefault should be true for distributed caches.
 long nextTimestamp()
          No clue what this is for, Hibernate docs don't say.
 void start(Properties properties)
           
 void stop()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MemcachedCacheProvider

public MemcachedCacheProvider()
Method Detail

buildCache

public org.hibernate.cache.Cache buildCache(String regionName,
                                            Properties properties)
                                     throws org.hibernate.cache.CacheException
Specified by:
buildCache in interface org.hibernate.cache.CacheProvider
Throws:
org.hibernate.cache.CacheException

instantiateKeyStrategy

protected KeyStrategy instantiateKeyStrategy(String cls)

nextTimestamp

public long nextTimestamp()
No clue what this is for, Hibernate docs don't say.

Specified by:
nextTimestamp in interface org.hibernate.cache.CacheProvider
Returns:
long Timestamper.next()

start

public void start(Properties properties)
           throws org.hibernate.cache.CacheException
Specified by:
start in interface org.hibernate.cache.CacheProvider
Throws:
org.hibernate.cache.CacheException

getMemcachedClientFactory

protected MemcacheClientFactory getMemcachedClientFactory(Config config)

stop

public void stop()
Specified by:
stop in interface org.hibernate.cache.CacheProvider

isMinimalPutsEnabledByDefault

public boolean isMinimalPutsEnabledByDefault()
According to the hibernate reference docs, MinimalPutsEnabledByDefault should be true for distributed caches.

Specified by:
isMinimalPutsEnabledByDefault in interface org.hibernate.cache.CacheProvider
Returns:
true


Copyright © 2015. All rights reserved.