Package de.umass.lastfm.cache
Class FileSystemCache
- java.lang.Object
-
- de.umass.lastfm.cache.Cache
-
- de.umass.lastfm.cache.FileSystemCache
-
- All Implemented Interfaces:
ScrobbleCache
public class FileSystemCache extends Cache implements ScrobbleCache
StandardCacheimplementation which is used by default by theCallerclass. 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.- Author:
- Janni Kovacs
-
-
Constructor Summary
Constructors Constructor Description FileSystemCache()FileSystemCache(java.io.File cacheDir)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcacheScrobble(SubmissionData... submissions)Caches one or moreSubmissionData.voidcacheScrobble(java.util.Collection<SubmissionData> submissions)Caches a collection ofSubmissionData.voidclear()Clears the cache by effectively removing all cached data.voidclearScrobbleCache()Clears all cached scrobbles from this cache.booleancontains(java.lang.String cacheEntryName)Checks if the cache contains an entry with the given name.booleanisEmpty()Checks if the cache contains any scrobbles.booleanisExpired(java.lang.String cacheEntryName)Checks if the specified entry is expired.java.io.InputStreamload(java.lang.String cacheEntryName)Loads the specified entry from the cache and returns an InputStream to be read from.voidremove(java.lang.String cacheEntryName)Removes the specified entry from the cache if available.voidscrobble(Scrobbler scrobbler)Tries to scrobble all cached scrobbles.voidstore(java.lang.String cacheEntryName, java.io.InputStream inputStream, long expirationDate)Stores a request in the cache.-
Methods inherited from class de.umass.lastfm.cache.Cache
createCacheEntryName, getExpirationPolicy, setExpirationPolicy, setHashCacheEntryNames
-
-
-
-
Method Detail
-
contains
public boolean contains(java.lang.String cacheEntryName)
Description copied from class:CacheChecks if the cache contains an entry with the given name.
-
remove
public void remove(java.lang.String cacheEntryName)
Description copied from class:CacheRemoves the specified entry from the cache if available. Does nothing if no such entry is available.
-
isExpired
public boolean isExpired(java.lang.String cacheEntryName)
Description copied from class:CacheChecks if the specified entry is expired.
-
clear
public void clear()
Description copied from class:CacheClears the cache by effectively removing all cached data.
-
load
public java.io.InputStream load(java.lang.String cacheEntryName)
Description copied from class:CacheLoads the specified entry from the cache and returns an InputStream to be read from. Returnsnullif the cache does not contain the specified cacheEntryName.
-
store
public void store(java.lang.String cacheEntryName, java.io.InputStream inputStream, long expirationDate)Description copied from class:CacheStores a request in the cache.
-
cacheScrobble
public void cacheScrobble(java.util.Collection<SubmissionData> submissions)
Description copied from interface:ScrobbleCacheCaches a collection ofSubmissionData.- Specified by:
cacheScrobblein interfaceScrobbleCache- Parameters:
submissions- The submissions
-
cacheScrobble
public void cacheScrobble(SubmissionData... submissions)
Description copied from interface:ScrobbleCacheCaches one or moreSubmissionData.- Specified by:
cacheScrobblein interfaceScrobbleCache- Parameters:
submissions- The submissions
-
isEmpty
public boolean isEmpty()
Description copied from interface:ScrobbleCacheChecks if the cache contains any scrobbles.- Specified by:
isEmptyin interfaceScrobbleCache- Returns:
trueif this cache is empty
-
scrobble
public void scrobble(Scrobbler scrobbler) throws java.io.IOException
Description copied from interface:ScrobbleCacheTries to scrobble all cached scrobbles. If it succeeds the cache will be empty afterwards. If this method fails an IOException is thrown and no entries are removed from the cache.- Specified by:
scrobblein interfaceScrobbleCache- Parameters:
scrobbler- AScrobblerinstance- Throws:
java.io.IOException- on I/O errors
-
clearScrobbleCache
public void clearScrobbleCache()
Description copied from interface:ScrobbleCacheClears all cached scrobbles from this cache.- Specified by:
clearScrobbleCachein interfaceScrobbleCache
-
-