Package de.umass.lastfm.cache
Class Cache
- java.lang.Object
-
- de.umass.lastfm.cache.Cache
-
- Direct Known Subclasses:
DatabaseCache,FileSystemCache,MemoryCache
public abstract class Cache extends java.lang.ObjectTheCachehandles 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:
Caller.setCache(Cache),ExpirationPolicy
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedCache()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidclear()Clears the cache by effectively removing all cached data.abstract booleancontains(java.lang.String cacheEntryName)Checks if the cache contains an entry with the given name.static java.lang.StringcreateCacheEntryName(java.lang.String method, java.util.Map<java.lang.String,java.lang.String> params)Creates a unique entry name string for a request.ExpirationPolicygetExpirationPolicy()Returns the activeExpirationPolicyabstract booleanisExpired(java.lang.String cacheEntryName)Checks if the specified entry is expired.abstract java.io.InputStreamload(java.lang.String cacheEntryName)Loads the specified entry from the cache and returns an InputStream to be read from.abstract voidremove(java.lang.String cacheEntryName)Removes 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(java.lang.String cacheEntryName, java.io.InputStream inputStream, long expirationDate)Stores a request in the cache.
-
-
-
Method Detail
-
getExpirationPolicy
public ExpirationPolicy getExpirationPolicy()
Returns the activeExpirationPolicy- Returns:
- the ExpirationPolicy
-
setExpirationPolicy
public void setExpirationPolicy(ExpirationPolicy expirationPolicy)
Sets the activeExpirationPolicy.- Parameters:
expirationPolicy- An ExpirationPolicy, notnull
-
contains
public abstract boolean contains(java.lang.String cacheEntryName)
Checks if the cache contains an entry with the given name.- Parameters:
cacheEntryName- An entry name- Returns:
trueif the cache contains this entry
-
load
public abstract java.io.InputStream load(java.lang.String cacheEntryName)
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
public abstract void remove(java.lang.String cacheEntryName)
Removes the specified entry from the cache if available. Does nothing if no such entry is available.- Parameters:
cacheEntryName- An entry name
-
store
public abstract void store(java.lang.String cacheEntryName, java.io.InputStream inputStream, long expirationDate)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
public abstract boolean isExpired(java.lang.String cacheEntryName)
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
public static java.lang.String createCacheEntryName(java.lang.String method, java.util.Map<java.lang.String,java.lang.String> params)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
-
-