Package org.red5.cache.impl
Class EhCacheImpl
- java.lang.Object
-
- org.red5.cache.impl.EhCacheImpl
-
- All Implemented Interfaces:
ICacheStore,Aware,ApplicationContextAware
public class EhCacheImpl extends Object implements ICacheStore, ApplicationContextAware
Provides an implementation of an object cache using EhCache.- Author:
- The Red5 Project, Paul Gregoire (mondain@gmail.com)
- See Also:
- ehcache homepage
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.slf4j.Loggerlog
-
Constructor Summary
Constructors Constructor Description EhCacheImpl()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddestroy()Allows for cleanup of a cache implementation.ICacheableget(String name)Return a cached object with the given name.static ApplicationContextgetApplicationContext()Getter for property 'applicationContext'.static longgetCacheHit()Getter for property 'cacheHit'.net.sf.ehcache.event.CacheManagerEventListenergetCacheManagerEventListener()Getter for property 'cacheManagerEventListener'.static longgetCacheMiss()Getter for property 'cacheMiss'.intgetDiskExpiryThreadIntervalSeconds()Getter for property 'diskExpiryThreadIntervalSeconds'.StringgetDiskStore()Getter for property 'diskStore'.StringgetMemoryStoreEvictionPolicy()Getter for property 'memoryStoreEvictionPolicy'.Iterator<String>getObjectNames()Return iterator over the names of all already loaded objects in the storage.Iterator<SoftReference<? extends ICacheable>>getObjects()Return iterator over the already loaded objects in the storage.voidinit()booleanoffer(String name, Object obj)Offer an object to the cache with an associated key.voidput(String name, Object obj)Puts an object in the cache with the associated key.booleanremove(String name)Delete the cached object with the given name.booleanremove(ICacheable obj)Delete the passed cached object.voidsetApplicationContext(ApplicationContext context)voidsetCacheConfigs(List<net.sf.ehcache.config.CacheConfiguration> configs)Setter for property 'cacheConfigs'.voidsetCacheManagerEventListener(net.sf.ehcache.event.CacheManagerEventListener cacheManagerEventListener)Setter for property 'cacheManagerEventListener'.voidsetDiskExpiryThreadIntervalSeconds(int diskExpiryThreadIntervalSeconds)Setter for property 'diskExpiryThreadIntervalSeconds'.voidsetDiskStore(String diskStore)Setter for property 'diskStore'.voidsetMaxEntries(int capacity)Sets the maximum number of entries for the cache.voidsetMemoryStoreEvictionPolicy(String memoryStoreEvictionPolicy)Setter for property 'memoryStoreEvictionPolicy'.
-
-
-
Method Detail
-
setApplicationContext
public void setApplicationContext(ApplicationContext context) throws BeansException
- Specified by:
setApplicationContextin interfaceApplicationContextAware- Throws:
BeansException
-
getApplicationContext
public static ApplicationContext getApplicationContext()
Getter for property 'applicationContext'.- Returns:
- Value for property 'applicationContext'.
-
init
public void init()
-
get
public ICacheable get(String name)
Return a cached object with the given name.- Specified by:
getin interfaceICacheStore- Parameters:
name- the name of the object to return- Returns:
- the object or
nullif no such object was found
-
put
public void put(String name, Object obj)
Puts an object in the cache with the associated key.- Specified by:
putin interfaceICacheStore- Parameters:
name- string name representing the objectobj- cacheable object
-
getObjectNames
public Iterator<String> getObjectNames()
Return iterator over the names of all already loaded objects in the storage.- Specified by:
getObjectNamesin interfaceICacheStore- Returns:
- iterator over all objects names
-
getObjects
public Iterator<SoftReference<? extends ICacheable>> getObjects()
Return iterator over the already loaded objects in the storage.- Specified by:
getObjectsin interfaceICacheStore- Returns:
- iterator over all objects
-
offer
public boolean offer(String name, Object obj)
Offer an object to the cache with an associated key. If the named object exists in cache, it will not be accepted.- Specified by:
offerin interfaceICacheStore- Parameters:
name- string name representing the objectobj- cacheable object- Returns:
- true if accepted, false otherwise
-
remove
public boolean remove(ICacheable obj)
Delete the passed cached object.- Specified by:
removein interfaceICacheStore- Parameters:
obj- the object to delete- Returns:
- true if was removed; false it wasn't in cache to begin with
-
remove
public boolean remove(String name)
Delete the cached object with the given name.- Specified by:
removein interfaceICacheStore- Parameters:
name- the name of the object to delete- Returns:
- true if was removed; false it wasn't in cache to begin with
-
setCacheConfigs
public void setCacheConfigs(List<net.sf.ehcache.config.CacheConfiguration> configs)
Setter for property 'cacheConfigs'.- Parameters:
configs- Value to set for property 'cacheConfigs'.
-
setMaxEntries
public void setMaxEntries(int capacity)
Sets the maximum number of entries for the cache.- Specified by:
setMaxEntriesin interfaceICacheStore- Parameters:
capacity- upper-limit of the cache
-
getMemoryStoreEvictionPolicy
public String getMemoryStoreEvictionPolicy()
Getter for property 'memoryStoreEvictionPolicy'.- Returns:
- Value for property 'memoryStoreEvictionPolicy'.
-
setMemoryStoreEvictionPolicy
public void setMemoryStoreEvictionPolicy(String memoryStoreEvictionPolicy)
Setter for property 'memoryStoreEvictionPolicy'.- Parameters:
memoryStoreEvictionPolicy- Value to set for property 'memoryStoreEvictionPolicy'.
-
getDiskExpiryThreadIntervalSeconds
public int getDiskExpiryThreadIntervalSeconds()
Getter for property 'diskExpiryThreadIntervalSeconds'.- Returns:
- Value for property 'diskExpiryThreadIntervalSeconds'.
-
setDiskExpiryThreadIntervalSeconds
public void setDiskExpiryThreadIntervalSeconds(int diskExpiryThreadIntervalSeconds)
Setter for property 'diskExpiryThreadIntervalSeconds'.- Parameters:
diskExpiryThreadIntervalSeconds- Value to set for property 'diskExpiryThreadIntervalSeconds'.
-
getDiskStore
public String getDiskStore()
Getter for property 'diskStore'.- Returns:
- Value for property 'diskStore'.
-
setDiskStore
public void setDiskStore(String diskStore)
Setter for property 'diskStore'.- Parameters:
diskStore- Value to set for property 'diskStore'.
-
getCacheManagerEventListener
public net.sf.ehcache.event.CacheManagerEventListener getCacheManagerEventListener()
Getter for property 'cacheManagerEventListener'.- Returns:
- Value for property 'cacheManagerEventListener'.
-
setCacheManagerEventListener
public void setCacheManagerEventListener(net.sf.ehcache.event.CacheManagerEventListener cacheManagerEventListener)
Setter for property 'cacheManagerEventListener'.- Parameters:
cacheManagerEventListener- Value to set for property 'cacheManagerEventListener'.
-
getCacheHit
public static long getCacheHit()
Getter for property 'cacheHit'.- Returns:
- Value for property 'cacheHit'.
-
getCacheMiss
public static long getCacheMiss()
Getter for property 'cacheMiss'.- Returns:
- Value for property 'cacheMiss'.
-
destroy
public void destroy()
Allows for cleanup of a cache implementation.- Specified by:
destroyin interfaceICacheStore
-
-