net.dontdrinkandroot.cache.impl
Class AbstractMapBackedCustomTtlCache<K,V,M extends MetaData>

java.lang.Object
  extended by net.dontdrinkandroot.cache.impl.AbstractCache<K,V>
      extended by net.dontdrinkandroot.cache.impl.AbstractMapBackedCache<K,V,M>
          extended by net.dontdrinkandroot.cache.impl.AbstractMapBackedCustomTtlCache<K,V,M>
All Implemented Interfaces:
Cache<K,V>, CustomTtlCache<K,V>
Direct Known Subclasses:
AbstractIndexedDiskCache, MemoryCache

public abstract class AbstractMapBackedCustomTtlCache<K,V,M extends MetaData>
extends AbstractMapBackedCache<K,V,M>
implements CustomTtlCache<K,V>

Author:
Philip W. Sorst

Field Summary
 
Fields inherited from interface net.dontdrinkandroot.cache.Cache
UNLIMITED_IDLE_TIME
 
Constructor Summary
AbstractMapBackedCustomTtlCache(String name, long defaultTimeToLive, ExpungeStrategy expungeStrategy)
          Construct a new AbstractCustomTtlCache.
AbstractMapBackedCustomTtlCache(String name, long defaultTimeToLive, long defaultMaxIdleTime, ExpungeStrategy expungeStrategy)
          Construct a new AbstractCustomTtlCache.
 
Method Summary
protected
<T extends V>
T
doPut(K key, T data)
          Performs storage of the given data and adds new metadata to the map.
protected abstract
<T extends V>
T
doPut(K key, T data, long timeToLive, long defaultMaxIdleTime)
          Performs storage of the given data and adds new metadata to the map.
<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, 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.
 
Methods inherited from class net.dontdrinkandroot.cache.impl.AbstractMapBackedCache
cleanUp, delete, delete, doDelete, doGet, expunge, get, getEntriesMetaData, getEntriesMetaDataMap, getExpungeStrategy, getMetaData, getStatistics, getWithErrors, put, putWithErrors, setEntriesMetaDataMap, setExpungeStrategy
 
Methods inherited from class net.dontdrinkandroot.cache.impl.AbstractCache
getCleanUpLogger, getDefaultMaxIdleTime, getDefaultTtl, getLogger, getName, setDefaultMaxIdleTime, setDefaultTtl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.dontdrinkandroot.cache.Cache
cleanUp, delete, get, getDefaultMaxIdleTime, getDefaultTtl, getMetaData, getName, getStatistics, getWithErrors, put, putWithErrors
 

Constructor Detail

AbstractMapBackedCustomTtlCache

public AbstractMapBackedCustomTtlCache(String name,
                                       long defaultTimeToLive,
                                       ExpungeStrategy expungeStrategy)
Construct a new AbstractCustomTtlCache.

Parameters:
name - The name of the cache.
defaultTimeToLive - The default Time to Live for Cache entries.

AbstractMapBackedCustomTtlCache

public AbstractMapBackedCustomTtlCache(String name,
                                       long defaultTimeToLive,
                                       long defaultMaxIdleTime,
                                       ExpungeStrategy expungeStrategy)
Construct a new AbstractCustomTtlCache.

Parameters:
name - The name of the cache.
defaultTimeToLive - The default Time to Live for Cache entries.
Method Detail

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.

putWithErrors

public final <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.

putWithErrors

public final <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.

doPut

protected <T extends V> T doPut(K key,
                                T data)
                     throws CacheException
Description copied from class: AbstractMapBackedCache
Performs storage of the given data and adds new metadata to the map.

Specified by:
doPut in class AbstractMapBackedCache<K,V,M extends MetaData>
Throws:
CacheException

doPut

protected abstract <T extends V> T doPut(K key,
                                         T data,
                                         long timeToLive,
                                         long defaultMaxIdleTime)
                              throws CacheException
Performs storage of the given data and adds new metadata to the map.

Throws:
CacheException


Copyright © 2013 dontdrinkandroot. All Rights Reserved.