Package de.umass.lastfm.cache
Class Cache
java.lang.Object
de.umass.lastfm.cache.Cache
- Direct Known Subclasses:
DatabaseCache,FileSystemCache,MemoryCache
The
Cache handles storing and loading to a permanent storage for last.fm api requests. This could be
a file system or a sql database.- Author:
- Janni Kovacs
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidclear()Clears the cache by effectively removing all cached data.abstract booleanChecks if the cache contains an entry with the given name.static StringcreateCacheEntryName(String method, Map<String, String> params) Creates a unique entry name string for a request.Returns the activeExpirationPolicyabstract booleanChecks if the specified entry is expired.abstract InputStreamLoads the specified entry from the cache and returns an InputStream to be read from.abstract voidRemoves the specified entry from the cache if available.voidsetExpirationPolicy(ExpirationPolicy expirationPolicy) Sets the activeExpirationPolicy.static voidsetHashCacheEntryNames(boolean hashCacheEntryNames) IfhashCacheEntryNamesis set to true thecreateCacheEntryName(java.lang.String, java.util.Map<java.lang.String, java.lang.String>)method will return a hash of the original entry name instead of the name itself.abstract voidstore(String cacheEntryName, InputStream inputStream, long expirationDate) Stores a request in the cache.
-
Constructor Details
-
Cache
protected Cache()
-
-
Method Details
-
getExpirationPolicy
Returns the activeExpirationPolicy- Returns:
- the ExpirationPolicy
-
setExpirationPolicy
Sets the activeExpirationPolicy.- Parameters:
expirationPolicy- An ExpirationPolicy, notnull
-
contains
Checks if the cache contains an entry with the given name.- Parameters:
cacheEntryName- An entry name- Returns:
trueif the cache contains this entry
-
load
Loads the specified entry from the cache and returns an InputStream to be read from. Returnsnullif the cache does not contain the specified cacheEntryName.- Parameters:
cacheEntryName- An entry name- Returns:
- an InputStream or
null
-
remove
Removes the specified entry from the cache if available. Does nothing if no such entry is available.- Parameters:
cacheEntryName- An entry name
-
store
Stores a request in the cache.- Parameters:
cacheEntryName- The entry name to be stored toinputStream- An InputStream containing the data to be cachedexpirationDate- The date of expiration represented in milliseconds since 1.1.1970
-
isExpired
Checks if the specified entry is expired.- Parameters:
cacheEntryName- An entry name- Returns:
trueif the entry is expired
-
clear
public abstract void clear()Clears the cache by effectively removing all cached data. -
createCacheEntryName
Creates a unique entry name string for a request. It consists of the method name and all the parameter names and values concatenated in alphabetical order. It is used to identify cache entries in the backend storage. IfhashCacheEntryNamesis set totruethis method will return a MD5 hash of the generated name.- Parameters:
method- The request methodparams- The request parameters- Returns:
- a cache entry name
-
setHashCacheEntryNames
public static void setHashCacheEntryNames(boolean hashCacheEntryNames) IfhashCacheEntryNamesis set to true thecreateCacheEntryName(java.lang.String, java.util.Map<java.lang.String, java.lang.String>)method will return a hash of the original entry name instead of the name itself.- Parameters:
hashCacheEntryNames-trueto generate hashes
-