net.dontdrinkandroot.cache.impl.disk.indexed
Class AbstractIndexedDiskCache<K extends Serializable,V extends Serializable>

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,BlockMetaData>
              extended by net.dontdrinkandroot.cache.impl.disk.indexed.AbstractIndexedDiskCache<K,V>
All Implemented Interfaces:
Cache<K,V>, CustomTtlCache<K,V>
Direct Known Subclasses:
ByteArrayIndexedDiskCache, SerializableIndexedDiskCache

public abstract class AbstractIndexedDiskCache<K extends Serializable,V extends Serializable>
extends AbstractMapBackedCustomTtlCache<K,V,BlockMetaData>

Author:
Philip W. Sorst

Field Summary
protected  DataFile dataFile
           
protected  IndexFile indexFile
           
protected  File lockFile
           
 
Fields inherited from interface net.dontdrinkandroot.cache.Cache
UNLIMITED_IDLE_TIME
 
Constructor Summary
AbstractIndexedDiskCache(String name, long defaultTimeToLive, ExpungeStrategy expungeStrategy, File baseDir)
           
AbstractIndexedDiskCache(String name, long defaultTimeToLive, long defaultMaxIdleTime, ExpungeStrategy expungeStrategy, File baseDir)
           
 
Method Summary
protected  Map<K,BlockMetaData> buildIndex()
           
 void close()
          Closes the cache.
protected abstract
<T extends V>
T
dataFromBytes(byte[] data)
           
protected abstract
<T extends V>
byte[]
dataToBytes(T data)
           
protected  void doDelete(K key, BlockMetaData metaData)
          Performs deletion of the data belonging to the metadata.
protected
<T extends V>
T
doGet(K key, BlockMetaData metaData)
          Performs retrieval of the data belonging to the metadata.
protected
<T extends V>
T
doPut(K key, T data, long timeToLive, long maxIdleTime)
          Performs storage of the given data and adds new metadata to the map.
 
Methods inherited from class net.dontdrinkandroot.cache.impl.AbstractMapBackedCustomTtlCache
doPut, put, put, putWithErrors, putWithErrors
 
Methods inherited from class net.dontdrinkandroot.cache.impl.AbstractMapBackedCache
cleanUp, delete, delete, 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
 

Field Detail

indexFile

protected final IndexFile indexFile

dataFile

protected final DataFile dataFile

lockFile

protected final File lockFile
Constructor Detail

AbstractIndexedDiskCache

public AbstractIndexedDiskCache(String name,
                                long defaultTimeToLive,
                                ExpungeStrategy expungeStrategy,
                                File baseDir)
                         throws IOException
Throws:
IOException

AbstractIndexedDiskCache

public AbstractIndexedDiskCache(String name,
                                long defaultTimeToLive,
                                long defaultMaxIdleTime,
                                ExpungeStrategy expungeStrategy,
                                File baseDir)
                         throws IOException
Throws:
IOException
Method Detail

close

public void close()
           throws IOException
Closes the cache.

Throws:
IOException

buildIndex

protected Map<K,BlockMetaData> buildIndex()
                                                        throws IOException
Throws:
IOException

doDelete

protected void doDelete(K key,
                        BlockMetaData metaData)
                 throws CacheException
Description copied from class: AbstractMapBackedCache
Performs deletion of the data belonging to the metadata. Removal from the map is done by the superclass.

Specified by:
doDelete in class AbstractMapBackedCache<K extends Serializable,V extends Serializable,BlockMetaData>
Throws:
CacheException

doGet

protected <T extends V> T doGet(K key,
                                BlockMetaData metaData)
                     throws CacheException
Description copied from class: AbstractMapBackedCache
Performs retrieval of the data belonging to the metadata.

Specified by:
doGet in class AbstractMapBackedCache<K extends Serializable,V extends Serializable,BlockMetaData>
Throws:
CacheException

doPut

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

Specified by:
doPut in class AbstractMapBackedCustomTtlCache<K extends Serializable,V extends Serializable,BlockMetaData>
Throws:
CacheException

dataFromBytes

protected abstract <T extends V> T dataFromBytes(byte[] data)
                                      throws CacheException
Throws:
CacheException

dataToBytes

protected abstract <T extends V> byte[] dataToBytes(T data)
                               throws CacheException
Throws:
CacheException


Copyright © 2013 dontdrinkandroot. All Rights Reserved.