public class JDBCDiskCache<K,V> extends AbstractDiskCache<K,V>
It expects a table created by the following script. The table name is configurable.
drop TABLE JCS_STORE; CREATE TABLE JCS_STORE ( CACHE_KEY VARCHAR(250) NOT NULL, REGION VARCHAR(250) NOT NULL, ELEMENT BLOB, CREATE_TIME TIMESTAMP, UPDATE_TIME_SECONDS BIGINT, MAX_LIFE_SECONDS BIGINT, SYSTEM_EXPIRE_TIME_SECONDS BIGINT, IS_ETERNAL CHAR(1), PRIMARY KEY (CACHE_KEY, REGION) );
The cleanup thread will delete non eternal items where (now - create time) > max life seconds * 1000
To speed up the deletion the SYSTEM_EXPIRE_TIME_SECONDS is used instead. It is recommended that an index be created on this column is you will have over a million records.
AbstractDiskCache.MyCacheListener
ICacheType.CacheType
NAME_COMPONENT_DELIMITER
Constructor and Description |
---|
JDBCDiskCache(JDBCDiskCacheAttributes cattr,
DataSourceFactory dsFactory,
TableState tableState)
Constructs a JDBC Disk Cache for the provided cache attributes.
|
Modifier and Type | Method and Description |
---|---|
String |
constructLikeParameterFromPattern(String pattern) |
protected int |
deleteExpired()
Removed the expired.
|
protected boolean |
doesElementExist(ICacheElement<K,V> ce,
Connection con)
Does an element exist for this key?
|
AuxiliaryCacheAttributes |
getAuxiliaryCacheAttributes()
This returns the generic attributes for an auxiliary cache.
|
DataSource |
getDataSource()
Public so managers can access it.
|
protected String |
getDiskLocation()
This is used by the event logging.
|
protected JDBCDiskCacheAttributes |
getJdbcDiskCacheAttributes() |
Set<K> |
getKeySet()
Return the keys in this cache.
|
int |
getSize()
Returns the current cache size.
|
IStats |
getStatistics()
Extends the parent stats.
|
protected String |
getTableName()
Returns the name of the table.
|
TableState |
getTableState() |
void |
processDispose()
Shuts down the pool
|
protected ICacheElement<K,V> |
processGet(K key)
Queries the database for the value.
|
protected Map<K,ICacheElement<K,V>> |
processGetMatching(String pattern)
This will run a like query.
|
protected boolean |
processRemove(K key)
Returns true if the removal was successful; or false if there is nothing to remove.
|
protected void |
processRemoveAll()
This should remove all elements.
|
protected void |
processUpdate(ICacheElement<K,V> ce)
Inserts or updates.
|
void |
reset()
Typically this is used to handle errors by last resort, force content update, or removeall
|
protected void |
setJdbcDiskCacheAttributes(JDBCDiskCacheAttributes jdbcDiskCacheAttributes) |
void |
setTableState(TableState tableState) |
String |
toString()
For debugging.
|
dispose, doDispose, doGet, doGetMatching, doRemove, doRemoveAll, doUpdate, get, getCacheName, getCacheType, getEventLoggingExtraInfo, getMatching, getStats, getStatus, isAlive, remove, removeAll, setAlive, update
disposeWithEventLogging, getMatchingWithEventLogging, getMultiple, getMultipleWithEventLogging, getWithEventLogging, removeAllWithEventLogging, removeWithEventLogging, updateWithEventLogging
createICacheEvent, createICacheEvent, getCacheEventLogger, getElementSerializer, getKeyMatcher, logApplicationEvent, logError, logICacheEvent, processGetMultiple, setCacheEventLogger, setElementSerializer, setKeyMatcher
public JDBCDiskCache(JDBCDiskCacheAttributes cattr, DataSourceFactory dsFactory, TableState tableState)
cattr
- the configuration object for this cachedsFactory
- the DataSourceFactory for this cachetableState
- an object to track table operationsprotected void processUpdate(ICacheElement<K,V> ce)
processUpdate
in class AbstractAuxiliaryCacheEventLogging<K,V>
ce
- protected boolean doesElementExist(ICacheElement<K,V> ce, Connection con)
ce
- the cache elementcon
- a database connectionprotected ICacheElement<K,V> processGet(K key)
processGet
in class AbstractAuxiliaryCacheEventLogging<K,V>
key
- AbstractDiskCache.get(Object)
protected Map<K,ICacheElement<K,V>> processGetMatching(String pattern)
processGetMatching
in class AbstractAuxiliaryCacheEventLogging<K,V>
pattern
- public String constructLikeParameterFromPattern(String pattern)
pattern
- protected boolean processRemove(K key)
processRemove
in class AbstractAuxiliaryCacheEventLogging<K,V>
key
- protected void processRemoveAll()
processRemoveAll
in class AbstractAuxiliaryCacheEventLogging<K,V>
protected int deleteExpired()
public void reset()
public void processDispose()
processDispose
in class AbstractAuxiliaryCacheEventLogging<K,V>
public int getSize()
getSize
in interface ICache<K,V>
getSize
in class AbstractDiskCache<K,V>
ICache.getSize()
public Set<K> getKeySet() throws IOException
getKeySet
in interface AuxiliaryCache<K,V>
getKeySet
in class AbstractDiskCache<K,V>
IOException
- if access to the auxiliary cache failsAbstractDiskCache.getKeySet()
protected void setJdbcDiskCacheAttributes(JDBCDiskCacheAttributes jdbcDiskCacheAttributes)
jdbcDiskCacheAttributes
- The jdbcDiskCacheAttributes to set.protected JDBCDiskCacheAttributes getJdbcDiskCacheAttributes()
public AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
AuxiliaryCache
public IStats getStatistics()
getStatistics
in interface AuxiliaryCache<K,V>
getStatistics
in class AbstractDiskCache<K,V>
AuxiliaryCache.getStatistics()
protected String getTableName()
public void setTableState(TableState tableState)
tableState
- The tableState to set.public TableState getTableState()
protected String getDiskLocation()
getDiskLocation
in class AbstractDiskCache<K,V>
public DataSource getDataSource() throws SQLException
SQLException
- if getting a data source failsCopyright © 2002–2023 The Apache Software Foundation. All rights reserved.