public abstract class Cache
extends java.lang.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(java.lang.String cacheEntryName)
Checks if the cache contains an entry with the given name.
|
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.
|
ExpirationPolicy |
getExpirationPolicy()
Returns the active
ExpirationPolicy |
abstract boolean |
isExpired(java.lang.String cacheEntryName)
Checks if the specified entry is expired.
|
abstract java.io.InputStream |
load(java.lang.String cacheEntryName)
Loads the specified entry from the cache and returns an InputStream to be read from.
|
abstract void |
remove(java.lang.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<java.lang.String, java.lang.String>) method will
return a hash of the original entry name instead of the name itself. |
abstract void |
store(java.lang.String cacheEntryName,
java.io.InputStream inputStream,
long expirationDate)
Stores a request in the cache.
|
public ExpirationPolicy getExpirationPolicy()
ExpirationPolicypublic void setExpirationPolicy(ExpirationPolicy expirationPolicy)
ExpirationPolicy.expirationPolicy - An ExpirationPolicy, not nullpublic abstract boolean contains(java.lang.String cacheEntryName)
cacheEntryName - An entry nametrue if the cache contains this entrypublic abstract java.io.InputStream load(java.lang.String cacheEntryName)
null
if the cache does not contain the specified cacheEntryName.cacheEntryName - An entry namenullpublic abstract void remove(java.lang.String cacheEntryName)
cacheEntryName - An entry namepublic abstract void store(java.lang.String cacheEntryName,
java.io.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(java.lang.String cacheEntryName)
cacheEntryName - An entry nametrue if the entry is expiredpublic abstract void clear()
public static java.lang.String createCacheEntryName(java.lang.String method,
java.util.Map<java.lang.String,java.lang.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<java.lang.String, java.lang.String>) method will
return a hash of the original entry name instead of the name itself.hashCacheEntryNames - true to generate hashes