net.dontdrinkandroot.cache.impl.memory

## Class NoopCache<K,V>

- java.lang.Object
- - net.dontdrinkandroot.cache.impl.memory.NoopCache<K,V>

All Implemented Interfaces:
  Cache<K,V>, CustomTtlCache<K,V>

    public class NoopCache<K,V>
    extends Object
    implements CustomTtlCache<K,V>

A serializable cache that does not actually perform any caching operation.

Author:
  Philip W. Sorst <philip@sorst.net>

### Field Summary

### Fields inherited from interface net.dontdrinkandroot.cache.Cache

`UNLIMITED_IDLE_TIME`

### Constructor Summary

Constructors
Constructor and Description
`NoopCache(String name)`

### Method Summary

Methods
`void` `cleanUp()` Cleanup the cache.
`void` `delete(K key)` Manually remove an entry from the cache.
`<T extends V> T` `get(K key)` Retrieve an entry from the cache if it is available.
`long` `getDefaultMaxIdleTime()` Get the default max idle time for cache entries.
`long` `getDefaultTtl()` Retrieve the default time to live for cache entries.
`MetaData` `getMetaData(K key)` Retrieve the `MetaData` of a cached entry if it is available.
`String` `getName()` Get the name of this cache.
`CacheStatistics` `getStatistics()` Get statistics of the cache like hitrate, or size.
`<T extends V> T` `getWithErrors(K key)` Retrieve an entry from the cache if it is available.
`<T extends V> T` `put(K key, T data)` Store an entry in the cache with the default time to live.
`<T extends V> T` `put(K key, T data, long timeToLive)` Store an entry in the cache with a specific time to live.
`<T extends V> T` `put(K key, T data, long timeToLive, long maxIdleTime)` Store an entry in the cache with a specific time to live and max idle time.
`<T extends V> T` `putWithErrors(K key, T data)` Store an entry in the cache with the default time to live.
`<T extends V> T` `putWithErrors(K key, T data, long timeToLive)` Store an entry in the cache with a specific time to live.
`<T extends V> T` `putWithErrors(K key, T data, long timeToLive, long maxIdleTime)` Store an entry in the cache with a specific time to live and max idle time.
`void` `setDefaultTtl(long defaultTTL)` Sets the default time to live for cache entries.
`void` `setName(String name)`

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

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

### Constructor Detail

#### NoopCache

    public NoopCache(String name)

### Method Detail

#### putWithErrors

    public <T extends V> T putWithErrors(K key,
                                T data)
                              throws CacheException

Description copied from interface: `Cache`
Store an entry in the cache with the default time to live.

Specified by:
  `putWithErrors` in interface `Cache<K,V>`
Parameters:
  `key` - A unique identifier.
  `data` - The data to store. Make sure that you don't alter the data after it has been put to cache as (depending on the implementation) this might lead to altering the entry in the cache. Use the returned data instead.
Returns:
  The entry that has been stored in the cache. It is save to alter this as implementations as implementations make sure that this is always (at least) a copy.
Throws:
  `CacheException` - Thrown on any errors encountered, supposed to include the stacktrace (if any).

#### getWithErrors

    public <T extends V> T getWithErrors(K key)
                              throws CacheException

Description copied from interface: `Cache`
Retrieve an entry from the cache if it is available.

Specified by:
  `getWithErrors` in interface `Cache<K,V>`
Parameters:
  `key` - The unique key under which the entry was stored.
Returns:
  The cache entry if it is valid and not expired, null otherwise.
Throws:
  `CacheException` - Thrown on any errors encountered, supposed to include the stacktrace (if any).

#### getMetaData

    public MetaData getMetaData(K key)
                         throws CacheException

Description copied from interface: `Cache`
Retrieve the `MetaData` of a cached entry if it is available.

Specified by:
  `getMetaData` in interface `Cache<K,V>`
Parameters:
  `key` - The key under which the entry was stored.
Returns:
  The `MetaData` of the entry if found, null otherwise.
Throws:
  `CacheException` - Thrown on any errors encountered, supposed to include the stacktrace (if any).

#### setDefaultTtl

    public void setDefaultTtl(long defaultTTL)

Description copied from interface: `Cache`
Sets the default time to live for cache entries.

Specified by:
  `setDefaultTtl` in interface `Cache<K,V>`
Parameters:
  `defaultTTL` - The default time to live for a cache entry in milliseconds.

#### getDefaultTtl

    public long getDefaultTtl()

Description copied from interface: `Cache`
Retrieve the default time to live for cache entries.

Specified by:
  `getDefaultTtl` in interface `Cache<K,V>`
Returns:
  The default time to live for a cache entry in milliseconds.

#### delete

    public void delete(K key)
                throws CacheException

Description copied from interface: `Cache`
Manually remove an entry from the cache.

Specified by:
  `delete` in interface `Cache<K,V>`
Parameters:
  `key` - The key under which the entry was stored.
Throws:
  `CacheException` - Thrown on any errors encountered, supposed to include the stacktrace (if any).

#### cleanUp

    public void cleanUp()

Description copied from interface: `Cache`
Cleanup the cache. Usually this means that expired entries are deleted but this can also incorporate optimization functions etc. depending on the implementation.

Specified by:
  `cleanUp` in interface `Cache<K,V>`

#### setName

    public void setName(String name)

#### getName

    public String getName()

Description copied from interface: `Cache`
Get the name of this cache.

Specified by:
  `getName` in interface `Cache<K,V>`
Returns:
  The name of this cache.

#### putWithErrors

    public <T extends V> T putWithErrors(K key,
                                T data,
                                long timeToLive)
                              throws CacheException

Description copied from interface: `CustomTtlCache`
Store an entry in the cache with a specific time to live.

Specified by:
  `putWithErrors` in interface `CustomTtlCache<K,V>`
  `data` - The data to store, make sure that you don't alter the data after it has been put to cache as (depending on the implementation) this might lead to altering the entry in the cache. Use the returned entry instead.
  `timeToLive` - The time (in milliseconds) after which the entry expires.
Returns:
  The entry that has been stored in the cache. It is save to alter this as implementations as implementations make sure that this is always a copy.
Throws:
  `CacheException` - Thrown if the storage fails.

#### getStatistics

    public CacheStatistics getStatistics()

Description copied from interface: `Cache`
Get statistics of the cache like hitrate, or size.

Specified by:
  `getStatistics` in interface `Cache<K,V>`
Returns:
  Statistics of the cache.

#### getDefaultMaxIdleTime

    public long getDefaultMaxIdleTime()

Description copied from interface: `Cache`
Get the default max idle time for cache entries.

Specified by:
  `getDefaultMaxIdleTime` in interface `Cache<K,V>`
Returns:
  The default max idle time for cache entries in milliseconds.

#### putWithErrors

    public <T extends V> T putWithErrors(K key,
                                T data,
                                long timeToLive,
                                long maxIdleTime)
                              throws CacheException

Description copied from interface: `CustomTtlCache`
Store an entry in the cache with a specific time to live and max idle time.

Specified by:
  `putWithErrors` in interface `CustomTtlCache<K,V>`
  `data` - The data to store, make sure that you don't alter the data after it has been put to cache as (depending on the implementation) this might lead to altering the entry in the cache. Use the returned entry instead.
  `timeToLive` - The time (in milliseconds) after which the entry expires.
  `maxIdleTime` - The time (in milliseconds) that an entry may idle (not being accessed) before being expunged.
Returns:
  The entry that has been stored in the cache. It is save to alter this as implementations as implementations make sure that this is always a copy.
Throws:
  `CacheException` - Thrown if the storage fails.

#### put

    public <T extends V> T put(K key,
                      T data)

Description copied from interface: `Cache`
Store an entry in the cache with the default time to live. Any errors are swallowed, use `Cache.putWithErrors(Object, Object)` if you want to handle them.

Specified by:
  `put` in interface `Cache<K,V>`
Parameters:
  `key` - A unique identifier.
  `data` - The data to store. Make sure that you don't alter the data after it has been put to cache as (depending on the implementation) this might lead to altering the entry in the cache. Use the returned data instead.
Returns:
  The entry that has been stored in the cache. It is save to alter this as implementations as implementations make sure that this is always (at least) a copy.

#### get

    public <T extends V> T get(K key)

Description copied from interface: `Cache`
Retrieve an entry from the cache if it is available. Any errors are swallowed, use `Cache.getWithErrors(Object)` if you want to handle them.

Specified by:
  `get` in interface `Cache<K,V>`
Parameters:
  `key` - The unique key under which the entry was stored.
Returns:
  The cache entry if it is valid and not expired, null otherwise.

#### put

    public <T extends V> T put(K key,
                      T data,
                      long timeToLive)

Description copied from interface: `CustomTtlCache`
Store an entry in the cache with a specific time to live. Any errors are swallowed, use `CustomTtlCache.put(Object, Object, long)` if you want to handle them.

Specified by:
  `put` in interface `CustomTtlCache<K,V>`
  `data` - The data to store, make sure that you don't alter the data after it has been put to cache as (depending on the implementation) this might lead to altering the entry in the cache. Use the returned entry instead.
  `timeToLive` - The time (in milliseconds) after which the entry expires.
Returns:
  The entry that has been stored in the cache. It is save to alter this as implementations as implementations make sure that this is always a copy.

#### put

    public <T extends V> T put(K key,
                      T data,
                      long timeToLive,
                      long maxIdleTime)

Description copied from interface: `CustomTtlCache`
Store an entry in the cache with a specific time to live and max idle time. Any errors are swallowed, use `CustomTtlCache.putWithErrors(Object, Object, long)` if you want to handle them.

Specified by:
  `put` in interface `CustomTtlCache<K,V>`
  `data` - The data to store, make sure that you don't alter the data after it has been put to cache as (depending on the implementation) this might lead to altering the entry in the cache. Use the returned entry instead.
  `timeToLive` - The time (in milliseconds) after which the entry expires.
  `maxIdleTime` - The time (in milliseconds) that an entry may idle (not being accessed) before being expunged.
Returns:
  The entry that has been stored in the cache. It is save to alter this as implementations as implementations make sure that this is always a copy.