Package com.tagtraum.core.cache
Class FileCache
- java.lang.Object
-
- com.tagtraum.core.cache.FileCache
-
- All Implemented Interfaces:
Cache
- Direct Known Subclasses:
CompressedFileCache
public class FileCache extends Object implements Cache
File system based cache.- Author:
- Hendrik Schreiber
-
-
Field Summary
-
Fields inherited from interface com.tagtraum.core.cache.Cache
IGNORE_AGE
-
-
Constructor Summary
Constructors Constructor Description FileCache()
File cache withDEFAULT_BASE_DIR
.FileCache(Path baseDir)
-
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.Path
getBaseDir()
String
getEntryFileExtension()
Cache
getNextCache()
Always returnsnull
.boolean
isCached(URL requestURL, long maxAge)
Indicates whether a certain object is in the cache.protected InputStream
openInputStream(Path file)
protected OutputStream
openOutputStream(Path file)
void
put(URL requestURL, byte[] object)
Puts an object into the cache.void
setBaseDir(Path baseDir)
void
setEntryFileExtension(String entryFileExtension)
Sets the file extension for each entry.void
setNextCache(Cache nextCache)
This feature is not supported by this cache implementation.
-
-
-
Constructor Detail
-
FileCache
public FileCache(Path baseDir)
- Parameters:
baseDir
- base directory for the cached files
-
FileCache
public FileCache()
File cache withDEFAULT_BASE_DIR
.
-
-
Method Detail
-
getBaseDir
public Path getBaseDir()
-
setBaseDir
public void setBaseDir(Path baseDir)
-
getEntryFileExtension
public String getEntryFileExtension()
-
setEntryFileExtension
public void setEntryFileExtension(String entryFileExtension)
Sets the file extension for each entry.- Parameters:
entryFileExtension
- extension incl. the "."
-
getNextCache
public Cache getNextCache()
Always returnsnull
.- Specified by:
getNextCache
in interfaceCache
- Returns:
- next cache or null
-
setNextCache
public void setNextCache(Cache nextCache)
This feature is not supported by this cache implementation.- 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
-
openInputStream
protected InputStream openInputStream(Path file) throws IOException
- Throws:
IOException
-
openOutputStream
protected OutputStream openOutputStream(Path file) throws IOException
- Throws:
IOException
-
-