org.red5.server.cache

## Class CacheImpl

- java.lang.Object
- - org.red5.server.cache.CacheImpl

All Implemented Interfaces:
  ICacheStore, org.springframework.context.ApplicationContextAware

    public class CacheImpl
    extends Object
    implements ICacheStore, org.springframework.context.ApplicationContextAware

Provides an implementation of an object cache.

Author:
  The Red5 Project (red5@osflash.org), Paul Gregoire (mondain@gmail.com)

### Field Summary

Fields
`protected static org.slf4j.Logger` `log`

### Method Summary

Methods
`void` `destroy()` Allows for cleanup of a cache implementation.
`ICacheable` `get(String name)` Return a cached object with the given name.
`static org.springframework.context.ApplicationContext` `getApplicationContext()` Getter for property 'applicationContext'.
`static long` `getCacheHit()` Getter for property 'cacheHit'.
`static long` `getCacheMiss()` Getter for property 'cacheMiss'.
`static CacheImpl` `getInstance()` Returns the instance of this class.
`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.
`void` `init()`
`boolean` `offer(String key, org.apache.mina.core.buffer.IoBuffer obj)`
`boolean` `offer(String name, Object obj)` Offer an object to the cache with an associated key.
`protected void` `put(String name, ICacheable obj)`
`void` `put(String name, Object obj)` Puts an object in the cache with the associated key.
`boolean` `remove(ICacheable obj)` Delete the passed cached object.
`boolean` `remove(String name)` Delete the cached object with the given name.
`void` `setApplicationContext(org.springframework.context.ApplicationContext context)`
`void` `setMaxEntries(int max)` Sets the maximum number of entries for the cache.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### log

    protected static org.slf4j.Logger log

### Method Detail

#### setApplicationContext

    public void setApplicationContext(org.springframework.context.ApplicationContext context)
                               throws org.springframework.beans.BeansException

Specified by:
  `setApplicationContext` in interface `org.springframework.context.ApplicationContextAware`
Throws:
  `org.springframework.beans.BeansException`

#### getApplicationContext

    public static org.springframework.context.ApplicationContext getApplicationContext()

Getter for property 'applicationContext'.

Returns:
  Value for property 'applicationContext'.

#### getInstance

    public static CacheImpl getInstance()

Returns the instance of this class.

Returns:
  instance of this class

#### init

    public void init()

#### getObjectNames

    public Iterator<String> getObjectNames()

Return iterator over the names of all already loaded objects in the storage.

Specified by:
  `getObjectNames` in interface `ICacheStore`
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:
  `getObjects` in interface `ICacheStore`
Returns:
  iterator over all objects

#### offer

    public boolean offer(String key,
                org.apache.mina.core.buffer.IoBuffer obj)

#### 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:
  `offer` in interface `ICacheStore`
Parameters:
  `name` - string name representing the object
  `obj` - cacheable object
Returns:
  true if accepted, false otherwise

#### put

    public void put(String name,
           Object obj)

Puts an object in the cache with the associated key.

Specified by:
  `put` in interface `ICacheStore`
Parameters:
  `name` - string name representing the object
  `obj` - cacheable object

#### put

    protected void put(String name,
           ICacheable obj)

#### get

    public ICacheable get(String name)

Return a cached object with the given name.

Specified by:
  `get` in interface `ICacheStore`
Parameters:
  `name` - the name of the object to return
Returns:
  the object or `null` if no such object was found

#### remove

    public boolean remove(ICacheable obj)

Delete the passed cached object.

Specified by:
  `remove` in interface `ICacheStore`
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:
  `remove` in interface `ICacheStore`
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 interface `ICacheStore`
Parameters:
  `max` - upper-limit of the cache

#### destroy

    public void destroy()

Allows for cleanup of a cache implementation.

Specified by:
  `destroy` in interface `ICacheStore`