public class FileSystemCache extends Cache implements ScrobbleCache
Cache
implementation which is used by default by the Caller
class.
This implementation caches all responses in the file system. In addition to the raw responses it stores a
.meta file which contains the expiration date for the specified request.Constructor and Description |
---|
FileSystemCache() |
FileSystemCache(java.io.File cacheDir) |
Modifier and Type | Method and Description |
---|---|
void |
cacheScrobble(java.util.Collection<SubmissionData> submissions)
Caches a collection of
SubmissionData . |
void |
cacheScrobble(SubmissionData... submissions)
Caches one or more
SubmissionData . |
void |
clear()
Clears the cache by effectively removing all cached data.
|
void |
clearScrobbleCache()
Clears all cached scrobbles from this cache.
|
boolean |
contains(java.lang.String cacheEntryName)
Checks if the cache contains an entry with the given name.
|
boolean |
isEmpty()
Checks if the cache contains any scrobbles.
|
boolean |
isExpired(java.lang.String cacheEntryName)
Checks if the specified entry is expired.
|
java.io.InputStream |
load(java.lang.String cacheEntryName)
Loads the specified entry from the cache and returns an InputStream to be read from.
|
void |
remove(java.lang.String cacheEntryName)
Removes the specified entry from the cache if available.
|
void |
scrobble(Scrobbler scrobbler)
Tries to scrobble all cached scrobbles.
|
void |
store(java.lang.String cacheEntryName,
java.io.InputStream inputStream,
long expirationDate)
Stores a request in the cache.
|
createCacheEntryName, getExpirationPolicy, setExpirationPolicy, setHashCacheEntryNames
public FileSystemCache()
public FileSystemCache(java.io.File cacheDir)
public boolean contains(java.lang.String cacheEntryName)
Cache
public void remove(java.lang.String cacheEntryName)
Cache
public boolean isExpired(java.lang.String cacheEntryName)
Cache
public void clear()
Cache
public java.io.InputStream load(java.lang.String cacheEntryName)
Cache
null
if the cache does not contain the specified cacheEntryName.public void store(java.lang.String cacheEntryName, java.io.InputStream inputStream, long expirationDate)
Cache
public void cacheScrobble(java.util.Collection<SubmissionData> submissions)
ScrobbleCache
SubmissionData
.cacheScrobble
in interface ScrobbleCache
submissions
- The submissionspublic void cacheScrobble(SubmissionData... submissions)
ScrobbleCache
SubmissionData
.cacheScrobble
in interface ScrobbleCache
submissions
- The submissionspublic boolean isEmpty()
ScrobbleCache
isEmpty
in interface ScrobbleCache
true
if this cache is emptypublic void scrobble(Scrobbler scrobbler) throws java.io.IOException
ScrobbleCache
scrobble
in interface ScrobbleCache
scrobbler
- A Scrobbler
instancejava.io.IOException
- on I/O errorspublic void clearScrobbleCache()
ScrobbleCache
clearScrobbleCache
in interface ScrobbleCache