net.dontdrinkandroot.cache.impl.disk.indexed
Class BufferedSerializableIndexedDiskCache

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<Serializable,Serializable>
                  extended by net.dontdrinkandroot.cache.impl.disk.indexed.SerializableIndexedDiskCache
                      extended by net.dontdrinkandroot.cache.impl.disk.indexed.BufferedSerializableIndexedDiskCache
All Implemented Interfaces:
Cache<Serializable,Serializable>, CustomTtlCache<Serializable,Serializable>
Direct Known Subclasses:
LruBufferedSerializableIndexedDiskCache

public class BufferedSerializableIndexedDiskCache
extends SerializableIndexedDiskCache

A SerializableIndexedDiskCache that buffers entries in memory on successful disk put and get operations. The size and contents of the buffer are determined by a buffer ExpungeStrategy that works the same way as a normal ExpungeStrategy but only on the buffer entries.

Author:
Philip W. Sorst

Field Summary
protected  ExpungeStrategy bufferExpungeStrategy
           
 
Fields inherited from class net.dontdrinkandroot.cache.impl.disk.indexed.AbstractIndexedDiskCache
dataFile, indexFile, lockFile
 
Fields inherited from interface net.dontdrinkandroot.cache.Cache
UNLIMITED_IDLE_TIME
 
Constructor Summary
BufferedSerializableIndexedDiskCache(String name, long defaultTimeToLive, ExpungeStrategy expungeStrategy, File baseDir, ExpungeStrategy bufferExpungeStrategy)
           
BufferedSerializableIndexedDiskCache(String name, long defaultTimeToLive, long defaultMaxIdleTime, ExpungeStrategy expungeStrategy, File baseDir, ExpungeStrategy bufferExpungeStrategy)
           
 
Method Summary
protected
<T extends Serializable>
T
copyData(T data)
          Creates a copy of the given data.
protected  void doDelete(Serializable key, BlockMetaData metaData)
          Performs deletion of the data belonging to the metadata.
protected
<T extends Serializable>
T
doGet(Serializable key, BlockMetaData metaData)
          Performs retrieval of the data belonging to the metadata.
protected
<T extends Serializable>
T
doPut(Serializable key, T data, long timeToLive, long maxIdleTime)
          Performs storage of the given data and adds new metadata to the map.
 SimpleCacheStatistics getBufferStatistics()
          Get the cache statistics of the buffer.
 boolean isCopyOnRead()
           
 boolean isCopyOnWrite()
           
 BufferedSerializableIndexedDiskCache setCopyOnRead(boolean copyOnRead)
          Sets if a successful get should return a copy of the cache entry, so when manipulating the object no changes are persisted in the buffer.
 BufferedSerializableIndexedDiskCache setCopyOnWrite(boolean copyOnWrite)
          Sets if a successful put should return a copy of the cache entry, so when manipulating the object no changes are persisted in the buffer.
 
Methods inherited from class net.dontdrinkandroot.cache.impl.disk.indexed.SerializableIndexedDiskCache
dataFromBytes, dataToBytes, getDataFileNumAllocatedBlocks, getIndexFileNumAllocatedBlocks
 
Methods inherited from class net.dontdrinkandroot.cache.impl.disk.indexed.AbstractIndexedDiskCache
buildIndex, close
 
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

bufferExpungeStrategy

protected final ExpungeStrategy bufferExpungeStrategy
Constructor Detail

BufferedSerializableIndexedDiskCache

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

BufferedSerializableIndexedDiskCache

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

getBufferStatistics

public SimpleCacheStatistics getBufferStatistics()
Get the cache statistics of the buffer. The buffer statistics indicate the following: a cache hit means that the entry exists in the cache and was found in the buffer, a cache miss means that the entry exists in the cache and was not found in the buffer, the get and put count reflects gets and puts to the buffer, not the cache itself, the size is the current size of the buffer.


doGet

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

Overrides:
doGet in class AbstractIndexedDiskCache<Serializable,Serializable>
Throws:
CacheException

doPut

protected <T extends Serializable> T doPut(Serializable 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.

Overrides:
doPut in class AbstractIndexedDiskCache<Serializable,Serializable>
Throws:
CacheException

doDelete

protected void doDelete(Serializable 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.

Overrides:
doDelete in class AbstractIndexedDiskCache<Serializable,Serializable>
Throws:
CacheException

copyData

protected <T extends Serializable> T copyData(T data)
Creates a copy of the given data.


isCopyOnRead

public boolean isCopyOnRead()

isCopyOnWrite

public boolean isCopyOnWrite()

setCopyOnRead

public BufferedSerializableIndexedDiskCache setCopyOnRead(boolean copyOnRead)
Sets if a successful get should return a copy of the cache entry, so when manipulating the object no changes are persisted in the buffer.


setCopyOnWrite

public BufferedSerializableIndexedDiskCache setCopyOnWrite(boolean copyOnWrite)
Sets if a successful put should return a copy of the cache entry, so when manipulating the object no changes are persisted in the buffer.



Copyright © 2013 dontdrinkandroot. All Rights Reserved.