Package de.umass.lastfm.cache
Class DatabaseCache
- java.lang.Object
-
- de.umass.lastfm.cache.Cache
-
- de.umass.lastfm.cache.DatabaseCache
-
public class DatabaseCache extends Cache
Generic class for caching into a database. It's constructor takes aConnectioninstance, which must be opened and closed by the client. SQL code used in this class should work with all common databases (which support varchar, timestamp and longvarchar datatypes).
For more specialized versions of this class for different databases one may extend this class and override methods as needed.- Author:
- Janni Kovacs
-
-
Field Summary
Fields Modifier and Type Field Description protected java.sql.Connectionconnprotected static java.lang.StringTABLE_NAME
-
Constructor Summary
Constructors Constructor Description DatabaseCache(java.sql.Connection connection)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears the cache by effectively removing all cached data.booleancontains(java.lang.String cacheEntryName)Checks if the cache contains an entry with the given name.protected voidcreateTable()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.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
-
-
-
-
Field Detail
-
TABLE_NAME
protected static final java.lang.String TABLE_NAME
- See Also:
- Constant Field Values
-
conn
protected java.sql.Connection conn
-
-
Method Detail
-
createTable
protected void createTable() throws java.sql.SQLException- Throws:
java.sql.SQLException
-
contains
public boolean contains(java.lang.String cacheEntryName)
Description copied from class:CacheChecks if the cache contains an entry with the given name.
-
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.
-
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.
-
store
public void store(java.lang.String cacheEntryName, java.io.InputStream inputStream, long expirationDate)Description copied from class:CacheStores a request in the cache.
-
isExpired
public boolean isExpired(java.lang.String cacheEntryName)
Description copied from class:CacheChecks if the specified entry is expired.
-
-