com.googlecode.hibernate.memcached
Class MemcachedCache
java.lang.Object
com.googlecode.hibernate.memcached.MemcachedCache
- All Implemented Interfaces:
- org.hibernate.cache.Cache
public class MemcachedCache
- extends Object
- implements org.hibernate.cache.Cache
Wrapper around MemcachedClient instance to provide the bridge between Hiberante and Memcached.
Uses the regionName given by Hibernate via the MemcachedCacheProvider
when generating cache keys.
All cache operations rely on using a KeyStrategy
to generate cache keys for use in memcached.
Support for the clear() operation is disabled by default.
There is no way for this instance of MemcachedCache to know what cache values to "clear" in a given Memcached instance.
Clear functionality is implemented by incrementing a "clearIndex" value that is always included in the cache-key generation.
When clear is called the memcached increment function is used to increment the global clean index. When clear is enabled,
every cache action taken starts with a call to memcached to 'get' the clearIndex counter. That value is then
applied to the cache key for the cache operation being taken. When the clearIndex is incremented this causes
the MemcachedCache to generate different cache-keys than it was before. This results in previously cached data being
abandoned in the cache, and left for memcached to deal with.
For these reasons it is not recommended to rely on clear() as a regular production functionality,
it is very expensive and generally not very useful anyway.
The MemcachedCache treats Hibernate cache regions as namespaces in Memcached. For more information see the
memcached FAQ.
- Author:
- Ray Krueger
DOGPILE_TOKEN
public static final Integer DOGPILE_TOKEN
MemcachedCache
public MemcachedCache(String regionName,
Memcache memcachedClient)
getCacheTimeSeconds
public int getCacheTimeSeconds()
setCacheTimeSeconds
public void setCacheTimeSeconds(int cacheTimeSeconds)
isClearSupported
public boolean isClearSupported()
setClearSupported
public void setClearSupported(boolean clearSupported)
isDogpilePreventionEnabled
public boolean isDogpilePreventionEnabled()
setDogpilePreventionEnabled
public void setDogpilePreventionEnabled(boolean dogpilePreventionEnabled)
getDogpilePreventionExpirationFactor
public double getDogpilePreventionExpirationFactor()
setDogpilePreventionExpirationFactor
public void setDogpilePreventionExpirationFactor(double dogpilePreventionExpirationFactor)
read
public Object read(Object key)
throws org.hibernate.cache.CacheException
- Specified by:
read in interface org.hibernate.cache.Cache
- Throws:
org.hibernate.cache.CacheException
get
public Object get(Object key)
throws org.hibernate.cache.CacheException
- Specified by:
get in interface org.hibernate.cache.Cache
- Throws:
org.hibernate.cache.CacheException
put
public void put(Object key,
Object value)
throws org.hibernate.cache.CacheException
- Specified by:
put in interface org.hibernate.cache.Cache
- Throws:
org.hibernate.cache.CacheException
update
public void update(Object key,
Object value)
throws org.hibernate.cache.CacheException
- Specified by:
update in interface org.hibernate.cache.Cache
- Throws:
org.hibernate.cache.CacheException
remove
public void remove(Object key)
throws org.hibernate.cache.CacheException
- Specified by:
remove in interface org.hibernate.cache.Cache
- Throws:
org.hibernate.cache.CacheException
clear
public void clear()
throws org.hibernate.cache.CacheException
- Clear functionality is disabled by default.
Read this class's javadoc for more detail.
- Specified by:
clear in interface org.hibernate.cache.Cache
- Throws:
org.hibernate.cache.CacheException- See Also:
MemcachedCache
destroy
public void destroy()
throws org.hibernate.cache.CacheException
- Specified by:
destroy in interface org.hibernate.cache.Cache
- Throws:
org.hibernate.cache.CacheException
lock
public void lock(Object key)
throws org.hibernate.cache.CacheException
- Specified by:
lock in interface org.hibernate.cache.Cache
- Throws:
org.hibernate.cache.CacheException
unlock
public void unlock(Object key)
throws org.hibernate.cache.CacheException
- Specified by:
unlock in interface org.hibernate.cache.Cache
- Throws:
org.hibernate.cache.CacheException
nextTimestamp
public long nextTimestamp()
- Specified by:
nextTimestamp in interface org.hibernate.cache.Cache
getTimeout
public int getTimeout()
- Specified by:
getTimeout in interface org.hibernate.cache.Cache
getRegionName
public String getRegionName()
- Specified by:
getRegionName in interface org.hibernate.cache.Cache
getSizeInMemory
public long getSizeInMemory()
- Specified by:
getSizeInMemory in interface org.hibernate.cache.Cache
getElementCountInMemory
public long getElementCountInMemory()
- Specified by:
getElementCountInMemory in interface org.hibernate.cache.Cache
getElementCountOnDisk
public long getElementCountOnDisk()
- Specified by:
getElementCountOnDisk in interface org.hibernate.cache.Cache
toMap
public Map<?,?> toMap()
- Specified by:
toMap in interface org.hibernate.cache.Cache
toString
public String toString()
- Overrides:
toString in class Object
getKeyStrategy
public KeyStrategy getKeyStrategy()
setKeyStrategy
public void setKeyStrategy(KeyStrategy keyStrategy)
Copyright © 2015. All rights reserved.