Package org.red5.cache.impl
Class CacheImpl
java.lang.Object
org.red5.cache.impl.CacheImpl
- All Implemented Interfaces:
ICacheStore
,Aware
,ApplicationContextAware
Provides an implementation of an object cache.
- Author:
- The Red5 Project, Paul Gregoire (mondain@gmail.com)
-
Field Summary
Modifier and TypeFieldDescriptionprivate static ApplicationContext
private static final Map<String,
SoftReference<? extends ICacheable>> private static AtomicLong
private static AtomicLong
private static int
private static CacheImpl
protected static org.slf4j.Logger
-
Constructor Summary
ModifierConstructorDescriptionprivate
This constructor helps to ensure that we are singleton. -
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy()
Allows for cleanup of a cache implementation.Return a cached object with the given name.static ApplicationContext
Getter for property 'applicationContext'.static long
Getter for property 'cacheHit'.static long
Getter for property 'cacheMiss'.static CacheImpl
Returns the instance of this class.Return iterator over the names of all already loaded objects in the storage.Iterator<SoftReference<? extends ICacheable>>
Return iterator over the already loaded objects in the storage.void
init()
boolean
Offer an object to the cache with an associated key.boolean
void
Puts an object in the cache with the associated key.protected void
put
(String name, ICacheable obj) boolean
Delete the cached object with the given name.boolean
remove
(ICacheable obj) Delete the passed cached object.void
setApplicationContext
(ApplicationContext context) void
setMaxEntries
(int max) Sets the maximum number of entries for the cache.
-
Field Details
-
log
protected static org.slf4j.Logger log -
instance
-
CACHE
-
registry
-
capacity
private static int capacity -
cacheHit
-
cacheMiss
-
applicationContext
-
-
Constructor Details
-
CacheImpl
private CacheImpl()This constructor helps to ensure that we are singleton.
-
-
Method Details
-
setApplicationContext
- Specified by:
setApplicationContext
in interfaceApplicationContextAware
- Throws:
BeansException
-
getApplicationContext
Getter for property 'applicationContext'.- Returns:
- Value for property 'applicationContext'.
-
getInstance
Returns the instance of this class.- Returns:
- instance of this class
-
init
public void init() -
getObjectNames
Return iterator over the names of all already loaded objects in the storage.- Specified by:
getObjectNames
in interfaceICacheStore
- Returns:
- iterator over all objects names
-
getObjects
Return iterator over the already loaded objects in the storage.- Specified by:
getObjects
in interfaceICacheStore
- Returns:
- iterator over all objects
-
offer
-
offer
Offer an object to the cache with an associated key. If the named object exists in cache, it will not be accepted.- Specified by:
offer
in interfaceICacheStore
- Parameters:
name
- string name representing the objectobj
- cacheable object- Returns:
- true if accepted, false otherwise
-
put
Puts an object in the cache with the associated key.- Specified by:
put
in interfaceICacheStore
- Parameters:
name
- string name representing the objectobj
- cacheable object
-
put
-
get
Return a cached object with the given name.- Specified by:
get
in interfaceICacheStore
- Parameters:
name
- the name of the object to return- Returns:
- the object or
null
if no such object was found
-
remove
Delete the passed cached object.- Specified by:
remove
in interfaceICacheStore
- Parameters:
obj
- the object to delete- Returns:
- true if was removed; false it wasn't in cache to begin with
-
remove
Delete the cached object with the given name.- Specified by:
remove
in interfaceICacheStore
- Parameters:
name
- the name of the object to delete- Returns:
- true if was removed; false it wasn't in cache to begin with
-
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'.
-
setMaxEntries
public void setMaxEntries(int max) Sets the maximum number of entries for the cache.- Specified by:
setMaxEntries
in interfaceICacheStore
- Parameters:
max
- upper-limit of the cache
-
destroy
public void destroy()Allows for cleanup of a cache implementation.- Specified by:
destroy
in interfaceICacheStore
-