Class JDBCDiskCache<K,V> 
java.lang.Object
org.apache.commons.jcs3.auxiliary.AbstractAuxiliaryCache<K,V>
 
org.apache.commons.jcs3.auxiliary.AbstractAuxiliaryCacheEventLogging<K,V>
 
org.apache.commons.jcs3.auxiliary.disk.AbstractDiskCache<K,V>
 
org.apache.commons.jcs3.auxiliary.disk.jdbc.JDBCDiskCache<K,V> 
- All Implemented Interfaces:
- AuxiliaryCache<K,,- V> - ICache<K,,- V> - ICacheType
- Direct Known Subclasses:
- MySQLDiskCache
This is the jdbc disk cache plugin.
 
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.
- 
Nested Class SummaryNested classes/interfaces inherited from class org.apache.commons.jcs3.auxiliary.disk.AbstractDiskCacheAbstractDiskCache.MyCacheListenerNested classes/interfaces inherited from interface org.apache.commons.jcs3.engine.behavior.ICacheTypeICacheType.CacheType
- 
Field SummaryFields inherited from interface org.apache.commons.jcs3.engine.behavior.ICacheNAME_COMPONENT_DELIMITER
- 
Constructor SummaryConstructorsConstructorDescriptionJDBCDiskCache(JDBCDiskCacheAttributes cattr, DataSourceFactory dsFactory, TableState tableState) Constructs a JDBC Disk Cache for the provided cache attributes.
- 
Method SummaryModifier and TypeMethodDescriptionconstructLikeParameterFromPattern(String pattern) protected intRemoved the expired.protected booleandoesElementExist(ICacheElement<K, V> ce, Connection con) Does an element exist for this key?This returns the generic attributes for an auxiliary cache.Public so managers can access it.protected StringThis is used by the event logging.protected JDBCDiskCacheAttributesReturn the keys in this cache.intgetSize()Returns the current cache size.Extends the parent stats.protected StringReturns the name of the table.voidShuts down the poolprotected 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 booleanprocessRemove(K key) Returns true if the removal was successful; or false if there is nothing to remove.protected voidThis should remove all elements.protected voidprocessUpdate(ICacheElement<K, V> ce) Inserts or updates.voidreset()Typically this is used to handle errors by last resort, force content update, or removeallprotected voidsetJdbcDiskCacheAttributes(JDBCDiskCacheAttributes jdbcDiskCacheAttributes) voidsetTableState(TableState tableState) toString()For debugging.Methods inherited from class org.apache.commons.jcs3.auxiliary.disk.AbstractDiskCachedispose, doDispose, doGet, doGetMatching, doRemove, doRemoveAll, doUpdate, get, getCacheName, getCacheType, getEventLoggingExtraInfo, getMatching, getStats, getStatus, isAlive, remove, removeAll, setAlive, updateMethods inherited from class org.apache.commons.jcs3.auxiliary.AbstractAuxiliaryCacheEventLoggingdisposeWithEventLogging, getMatchingWithEventLogging, getMultiple, getMultipleWithEventLogging, getWithEventLogging, removeAllWithEventLogging, removeWithEventLogging, updateWithEventLoggingMethods inherited from class org.apache.commons.jcs3.auxiliary.AbstractAuxiliaryCachecreateICacheEvent, createICacheEvent, getCacheEventLogger, getElementSerializer, getKeyMatcher, logApplicationEvent, logError, logICacheEvent, processGetMultiple, setCacheEventLogger, setElementSerializer, setKeyMatcher
- 
Constructor Details- 
JDBCDiskCachepublic JDBCDiskCache(JDBCDiskCacheAttributes cattr, DataSourceFactory dsFactory, TableState tableState) Constructs a JDBC Disk Cache for the provided cache attributes. The table state object is used to mark deletions.- Parameters:
- cattr- the configuration object for this cache
- dsFactory- the DataSourceFactory for this cache
- tableState- an object to track table operations
 
 
- 
- 
Method Details- 
processUpdateInserts or updates. By default it will try to insert. If the item exists we will get an error. It will then update. This behavior is configurable. The cache can be configured to check before inserting.- Specified by:
- processUpdatein class- AbstractAuxiliaryCacheEventLogging<K,- V> 
- Parameters:
- ce-
 
- 
doesElementExistDoes an element exist for this key?- Parameters:
- ce- the cache element
- con- a database connection
- Returns:
- boolean
 
- 
processGetQueries the database for the value. If it gets a result, the value is deserialized.- Specified by:
- processGetin class- AbstractAuxiliaryCacheEventLogging<K,- V> 
- Parameters:
- key-
- Returns:
- ICacheElement
- See Also:
 
- 
processGetMatchingThis will run a like query. It will try to construct a usable query but different implementations will be needed to adjust the syntax.- Specified by:
- processGetMatchingin class- AbstractAuxiliaryCacheEventLogging<K,- V> 
- Parameters:
- pattern-
- Returns:
- key,value map
 
- 
constructLikeParameterFromPattern- Parameters:
- pattern-
- Returns:
- String to use in the like query.
 
- 
processRemoveReturns true if the removal was successful; or false if there is nothing to remove. Current implementation always results in a disk orphan.- Specified by:
- processRemovein class- AbstractAuxiliaryCacheEventLogging<K,- V> 
- Parameters:
- key-
- Returns:
- boolean
 
- 
processRemoveAllThis should remove all elements. The auxiliary can be configured to forbid this behavior. If remove all is not allowed, the method balks.- Specified by:
- processRemoveAllin class- AbstractAuxiliaryCacheEventLogging<K,- V> 
 
- 
deleteExpiredRemoved the expired. (now - create time) > max life seconds * 1000- Returns:
- the number deleted
 
- 
resetTypically this is used to handle errors by last resort, force content update, or removeall
- 
processDisposeShuts down the pool- Specified by:
- processDisposein class- AbstractAuxiliaryCacheEventLogging<K,- V> 
 
- 
getSizeReturns the current cache size. Just does a count(*) for the region.
- 
getKeySetReturn the keys in this cache.- Specified by:
- getKeySetin interface- AuxiliaryCache<K,- V> 
- Specified by:
- getKeySetin class- AbstractDiskCache<K,- V> 
- Returns:
- a set of the key type TODO This should probably be done in chunks with a range passed in. This will be a problem if someone puts a 1,000,000 or so items in a region.
- Throws:
- IOException- if access to the auxiliary cache fails
- See Also:
 
- 
setJdbcDiskCacheAttributes- Parameters:
- jdbcDiskCacheAttributes- The jdbcDiskCacheAttributes to set.
 
- 
getJdbcDiskCacheAttributes- Returns:
- Returns the jdbcDiskCacheAttributes.
 
- 
getAuxiliaryCacheAttributesDescription copied from interface:AuxiliaryCacheThis returns the generic attributes for an auxiliary cache. Most implementations will cast this to a more specific type.- Returns:
- Returns the AuxiliaryCacheAttributes.
 
- 
getStatisticsExtends the parent stats.- Specified by:
- getStatisticsin interface- AuxiliaryCache<K,- V> 
- Overrides:
- getStatisticsin class- AbstractDiskCache<K,- V> 
- Returns:
- IStats
- See Also:
 
- 
getTableNameReturns the name of the table.- Returns:
- the table name or UNDEFINED
 
- 
setTableState- Parameters:
- tableState- The tableState to set.
 
- 
getTableState- Returns:
- Returns the tableState.
 
- 
getDiskLocationThis is used by the event logging.- Specified by:
- getDiskLocationin class- AbstractDiskCache<K,- V> 
- Returns:
- the location of the disk, either path or ip.
 
- 
getDataSourcePublic so managers can access it.- Returns:
- the dsFactory
- Throws:
- SQLException- if getting a data source fails
 
- 
toStringFor debugging.
 
-