K - The type of the key. Usually its StringV - The type of the value. Usually Object, if you want to create a all in one cache.public interface Cache<K,V>
MemoryCache: Can be accessed directly and should have O(1) implementation. The requested object is already in memory and does not need to be parsedDiskCache: Is a cache that must be read from disk. The real object must be parsed and therefore it can take some time to query this type of cache| Modifier and Type | Method and Description |
|---|---|
void |
addDiskCache(DiskCache<K,V> cache)
Add a disk cache
|
void |
addMemoryCache(MemoryCache<K,V> cache)
Adds a memory cache
|
void |
clear()
Cleans the cache, by removing all cache entries
|
CacheEntry<V> |
getFromDiskCache(K key,
Class<?> targetClass,
int collectionType)
Get a value from the cache by passing additional information for the
ParserWriter |
CacheEntry<V> |
getFromMemoryCache(K key)
Do a quick look up.
|
ParserWriterPool |
getParserWriterPool()
Get the
ParserWriterPool. |
void |
onLowMemory()
This method is called, when the memory of the device runs low (RAM).
|
void |
putRawToDiskCache(K key,
byte[] value,
String mimeType,
String charsetEncoding,
Long expirationTimeStamp,
String eTag)
Write as raw bytes
|
void |
putToDiskCache(K key,
V value,
String mimeType,
String charsetEncoding,
Long expirationTimeStamp,
String eTag)
Write
|
void |
putToMemoryCache(K key,
CacheEntry<V> value)
Put a already existing
CacheEntry to the memory cache. |
void |
putToMemoryCache(K key,
V value,
String mimeType,
String charsetEncoding,
Long expirationTimeStamp,
String eTag)
Adds and create a new
CacheEntry to the cache. |
void |
remove(K key)
Removes the Entry
|
void |
removeDiskCache(DiskCache<K,V> cache)
remove a Disk cache
|
void |
removeMemoryCache(MemoryCache<K,V> cache)
remove a memory cache
|
void |
updateExpirationTimestamp(K key,
long expirationTimestamp)
Updates the cached entries expiration timestamp (identified by the key)
|
CacheEntry<V> getFromDiskCache(K key, Class<?> targetClass, int collectionType) throws Exception
ParserWriterkey - The keytargetClass - The target class, to where the retrieved entry should be
mapped (with an objectmapper)collectionType - The returning collection type, like List, etc. This must be
one of the constatns specified int
ParserWriter.COLLECTION_TYPE_NONE,
ParserWriter.COLLECTION_TYPE_LIST, etc. ...ExceptionCacheEntry<V> getFromMemoryCache(K key)
key - The keyvoid addMemoryCache(MemoryCache<K,V> cache)
cache - void removeMemoryCache(MemoryCache<K,V> cache)
cache - void putToMemoryCache(K key, V value, String mimeType, String charsetEncoding, Long expirationTimeStamp, String eTag)
CacheEntry to the cache.key - The keyvalue - The Value for the given keymimeType - The mime type of the value. This is important to find the
correct parser for the stored cache valuecharsetEncoding - The charset like, UTF-8 etc. that is used, to encode the
string content (is useless for binary data)expirationTimeStamp - The expiration valueeTag - The ETagvoid putToMemoryCache(K key, CacheEntry<V> value)
CacheEntry to the memory cache.
This will normally be called if you want to put a entry retrieved from disc cache to the memekey - value - void putToDiskCache(K key, V value, String mimeType, String charsetEncoding, Long expirationTimeStamp, String eTag) throws Exception
key - value - mimeType - charsetEncoding - expirationTimeStamp - eTag - Exceptionvoid putRawToDiskCache(K key, byte[] value, String mimeType, String charsetEncoding, Long expirationTimeStamp, String eTag) throws Exception
key - value - mimeType - charsetEncoding - expirationTimeStamp - eTag - Exceptionvoid remove(K key) throws IOException
key - IOExceptionParserWriterPool getParserWriterPool()
ParserWriterPool.
Add in there any ParserWriter your cache should be able to handle and parsevoid onLowMemory()
void clear()
throws IOException
IOExceptionvoid updateExpirationTimestamp(K key, long expirationTimestamp) throws IOException
key - expirationTimestamp - IOExceptionCopyright © 2015 Hannes Dorfmann. All rights reserved.