de.umass.lastfm.cache
public abstract class Cache extends Object
Cache
handles storing and loading to a permanent storage for last.fm api requests. This could be
a file system or a sql database.Caller.setCache(Cache)
,
ExpirationPolicy
Modifier | Constructor and Description |
---|---|
protected |
Cache() |
Modifier and Type | Method and Description |
---|---|
abstract void |
clear()
Clears the cache by effectively removing all cached data.
|
abstract boolean |
contains(String cacheEntryName)
Checks if the cache contains an entry with the given name.
|
static String |
createCacheEntryName(String method,
Map<String,String> params)
Creates a unique entry name string for a request.
|
ExpirationPolicy |
getExpirationPolicy()
Returns the active
ExpirationPolicy |
abstract boolean |
isExpired(String cacheEntryName)
Checks if the specified entry is expired.
|
abstract InputStream |
load(String cacheEntryName)
Loads the specified entry from the cache and returns an InputStream to be read from.
|
abstract void |
remove(String cacheEntryName)
Removes the specified entry from the cache if available.
|
void |
setExpirationPolicy(ExpirationPolicy expirationPolicy)
Sets the active
ExpirationPolicy . |
static void |
setHashCacheEntryNames(boolean hashCacheEntryNames)
If
hashCacheEntryNames is set to true the createCacheEntryName(java.lang.String, java.util.Map method will
return a hash of the original entry name instead of the name itself. |
abstract void |
store(String cacheEntryName,
InputStream inputStream,
long expirationDate)
Stores a request in the cache.
|
public ExpirationPolicy getExpirationPolicy()
ExpirationPolicy
public void setExpirationPolicy(ExpirationPolicy expirationPolicy)
ExpirationPolicy
.expirationPolicy
- An ExpirationPolicy, not null
public abstract boolean contains(String cacheEntryName)
cacheEntryName
- An entry nametrue
if the cache contains this entrypublic abstract InputStream load(String cacheEntryName)
null
if the cache does not contain the specified cacheEntryName.cacheEntryName
- An entry namenull
public abstract void remove(String cacheEntryName)
cacheEntryName
- An entry namepublic abstract void store(String cacheEntryName, InputStream inputStream, long expirationDate)
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.1970public abstract boolean isExpired(String cacheEntryName)
cacheEntryName
- An entry nametrue
if the entry is expiredpublic abstract void clear()
public static String createCacheEntryName(String method, Map<String,String> params)
hashCacheEntryNames
is set to true
this method will return a MD5 hash of
the generated name.method
- The request methodparams
- The request parameterspublic static void setHashCacheEntryNames(boolean hashCacheEntryNames)
hashCacheEntryNames
is set to true the createCacheEntryName(java.lang.String, java.util.Map)
method will
return a hash of the original entry name instead of the name itself.hashCacheEntryNames
- true
to generate hashes