Package com.tagtraum.core.cache
Class LRUCache
- java.lang.Object
-
- com.tagtraum.core.cache.LRUCache
-
- All Implemented Interfaces:
Cache
public class LRUCache extends Object implements Cache
LRUCache that utilizes SoftReferences.- Author:
- Hendrik Schreiber
-
-
Field Summary
-
Fields inherited from interface com.tagtraum.core.cache.Cache
IGNORE_AGE
-
-
Constructor Summary
Constructors Constructor Description LRUCache()
Cache withDEFAULT_CACHE_CAPACITY
.LRUCache(int capacity)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clears the cache and all other caches in the cache chain.void
clear(long maxAge)
Clears the cache and all other caches in the cache chain.byte[]
get(URL requestURL, long maxAge)
Retrieves an object from the cache.Cache
getNextCache()
Returns the next cache in a chain of caches.boolean
isCached(URL requestURL, long maxAge)
Indicates whether a certain object is in the cache.boolean
isWriteThrough()
void
put(URL requestURL, byte[] object)
Puts an object into the cache.void
setNextCache(Cache nextCache)
Registers the next cache.void
setWriteThrough(boolean writeThrough)
-
-
-
Constructor Detail
-
LRUCache
public LRUCache(int capacity)
- Parameters:
capacity
- capacity of this cache
-
LRUCache
public LRUCache()
Cache withDEFAULT_CACHE_CAPACITY
.
-
-
Method Detail
-
isWriteThrough
public boolean isWriteThrough()
-
setWriteThrough
public void setWriteThrough(boolean writeThrough)
-
getNextCache
public Cache getNextCache()
Description copied from interface:Cache
Returns the next cache in a chain of caches.- Specified by:
getNextCache
in interfaceCache
- Returns:
- next cache or null
-
setNextCache
public void setNextCache(Cache nextCache)
Description copied from interface:Cache
Registers the next cache.- Specified by:
setNextCache
in interfaceCache
- Parameters:
nextCache
- next cache
-
isCached
public boolean isCached(URL requestURL, long maxAge) throws IOException
Description copied from interface:Cache
Indicates whether a certain object is in the cache.- Specified by:
isCached
in interfaceCache
- Parameters:
requestURL
- keymaxAge
- maximal allowed age in ms, a negative value implies age does not matter.- Returns:
- true or false
- Throws:
IOException
- if an IOException occurs
-
clear
public void clear(long maxAge)
Description copied from interface:Cache
Clears the cache and all other caches in the cache chain.
-
clear
public void clear()
Description copied from interface:Cache
Clears the cache and all other caches in the cache chain.
-
get
public byte[] get(URL requestURL, long maxAge) throws IOException
Description copied from interface:Cache
Retrieves an object from the cache.- Specified by:
get
in interfaceCache
- Parameters:
requestURL
- keymaxAge
- max age in ms, a negative value implies age does not matter.- Returns:
- the object or null, if not found
- Throws:
IOException
- if an IOException occurs
-
put
public void put(URL requestURL, byte[] object) throws IOException
Description copied from interface:Cache
Puts an object into the cache.- Specified by:
put
in interfaceCache
- Parameters:
requestURL
- keyobject
- byte array to cache- Throws:
IOException
- if an IOException occurs
-
-