|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.objectweb.cjdbc.controller.cache.result.AbstractResultCache
org.objectweb.cjdbc.controller.cache.result.ResultCache
This is a query cache implementation with tunable granularity.
Cache invalidation granularity can take on of the following values:
NO_INVALIDATE: no invalidation, the cache is
inconsistent and this should just be used to determine hit ratio upper bound.
DATABASE: the cache is flushed each time the database is
updated (every INSERT, UPDATE, DELETE, ... statement).TABLE: table granularity, entries in the cache are
invalidated based on table dependencies.COLUMN: column granularity, entries in the cache are
invalidated based on column dependenciesCOLUMN_UNIQUE: same as COLUMN except that
UNIQUE queries that selects a single row based on a key are
invalidated only when needed.
| Field Summary | |
private java.util.HashSet |
cachingRules
|
protected CacheDatabaseSchema |
cdbs
|
private ResultCacheRule |
defaultRule
|
private java.util.ArrayList |
eagerCache
|
private EagerCacheThread |
eagerThread
|
private boolean |
flushingCache
|
private AbstractResultCacheEntry |
lruHead
|
private AbstractResultCacheEntry |
lruTail
|
private int |
maxEntries
|
private java.util.HashSet |
pendingQueries
|
private long |
pendingQueryTimeout
Pending query timeout in ms. |
private java.util.HashMap |
queries
|
private java.util.ArrayList |
relaxedCache
|
private RelaxedCacheThread |
relaxedThread
|
private CacheStatistics |
stats
|
private static boolean[] |
TRUE_TRUE
|
| Fields inherited from class org.objectweb.cjdbc.controller.cache.result.AbstractResultCache |
logger, parsingGranularity |
| Fields inherited from interface org.objectweb.cjdbc.common.xml.XmlComponent |
DOCTYPE_CONTROLLER, DOCTYPE_DB, XML_VERSION |
| Constructor Summary | |
ResultCache(int maxEntries,
int pendingTimeout)
Creates a new Cache instance. |
|
| Method Summary | |
void |
addCachingRule(ResultCacheRule rule)
Add a rule for this ResultCache |
void |
addToCache(SelectRequest request,
ControllerResultSet result)
Adds an entry request/reply to the cache. |
void |
commit(long transactionId)
Commit a transaction given its id. |
void |
flushCache()
Removes all entries from the cache. |
private CacheBehavior |
getCacheBehavior(SelectRequest request)
Finds the behavior of the cache with the given query skeleton. |
java.lang.String[][] |
getCacheData()
Returns the content of the cache as displayable array of array of string |
private java.lang.String |
getCacheKeyFromRequest(SelectRequest request)
Creates a unique cache entry key from the given request. |
long |
getCacheSize()
Get Cache size |
CacheStatistics |
getCacheStatistics()
Returns pointer to the stats collector |
java.lang.String[][] |
getCacheStatsData()
Returns a bunch of stats collected by the cache, such as cache hits. |
ResultCacheRule |
getDefaultRule()
Return the default cache rule |
java.util.ArrayList |
getEagerCache()
Returns the eagerCache value. |
AbstractResultCacheEntry |
getFromCache(SelectRequest request,
boolean addToPendingQueries)
Gets the result to the given request from the cache. |
abstract java.lang.String |
getName()
Retrieve the name of this cache |
int |
getParsingGranularity()
Gets the needed query parsing granularity. |
int |
getPendingQueryTimeout()
Returns the pending query timeout in seconds. |
java.util.HashMap |
getQueries()
Possibly we want to access the queries in the cache for timing purposes |
java.util.ArrayList |
getRelaxedCache()
Returns the relaxedCache value. |
protected java.lang.String |
getXmlImpl()
Gets information about the request cache |
abstract boolean |
isUpdateNecessary(UpdateRequest request)
Returns true if the cache does not contain the values that are given in the update statement. |
void |
mergeDatabaseSchema(DatabaseSchema dbs)
Merge the given DatabaseSchema with the current one. |
boolean[] |
needInvalidate(ControllerResultSet result,
UpdateRequest request)
Do we need invalidation after an update request, given a ControllerResultSet. |
protected abstract void |
processAddToCache(AbstractResultCacheEntry qe)
Process the add to cache to update implementation specific data structures. |
protected abstract void |
processWriteNotify(AbstractWriteRequest request)
Implementation specific invalidation of the cache. |
void |
removeFromCache(SelectRequest request)
Removes an entry from the cache (both request and reply are dropped). |
void |
removeFromPendingQueries(SelectRequest request)
Removes an entry from the pending query list. |
private void |
removeOldest()
Removes the oldest entry from the cache. |
void |
rollback(long transactionId)
Rollback a transaction given its id. |
void |
setDatabaseSchema(DatabaseSchema dbs)
Sets the DatabaseSchema of the current virtual database. |
void |
setDefaultRule(ResultCacheRule defaultRule)
Set the default query rule |
void |
setPendingQueryTimeout(int pendingQueryTimeout)
Sets the pending query timeout in seconds. |
void |
shutdown()
Shutdown the result cache and all its threads. |
void |
writeNotify(AbstractWriteRequest request)
Notifies the cache that this write request has been issued, so that cache coherency can be maintained. |
| Methods inherited from class org.objectweb.cjdbc.controller.cache.result.AbstractResultCache |
getXml, setParsingGranularity |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
private int maxEntries
private long pendingQueryTimeout
private java.util.HashMap queries
private java.util.HashSet pendingQueries
private java.util.HashSet cachingRules
private ResultCacheRule defaultRule
private java.util.ArrayList relaxedCache
private AbstractResultCacheEntry lruHead
private AbstractResultCacheEntry lruTail
protected CacheDatabaseSchema cdbs
private CacheStatistics stats
private RelaxedCacheThread relaxedThread
private static final boolean[] TRUE_TRUE
private boolean flushingCache
private EagerCacheThread eagerThread
private java.util.ArrayList eagerCache
| Constructor Detail |
public ResultCache(int maxEntries,
int pendingTimeout)
Cache instance.
maxEntries - maximum number of cache entriespendingTimeout - pending queries timeout| Method Detail |
public void shutdown()
shutdown in class AbstractResultCachepublic int getPendingQueryTimeout()
setPendingQueryTimeout(int)public void setPendingQueryTimeout(int pendingQueryTimeout)
pendingQueryTimeout - the pending query timeout to set.getPendingQueryTimeout()public java.util.HashMap getQueries()
HashMap of queries (not synchronized)public void setDatabaseSchema(DatabaseSchema dbs)
DatabaseSchema of the current virtual database.
setDatabaseSchema in class AbstractResultCachedbs - a DatabaseSchema valueCacheDatabaseSchemapublic void mergeDatabaseSchema(DatabaseSchema dbs)
DatabaseSchema with the current one.
mergeDatabaseSchema in class AbstractResultCachedbs - a DatabaseSchema valueCacheDatabaseSchemapublic void addCachingRule(ResultCacheRule rule)
ResultCache
addCachingRule in class AbstractResultCacherule - that contains information on the action to perform for a
specific queryResultCacheRulepublic ResultCacheRule getDefaultRule()
AbstractResultCache
getDefaultRule in class AbstractResultCacheAbstractResultCache.getDefaultRule()public void setDefaultRule(ResultCacheRule defaultRule)
AbstractResultCache
setDefaultRule in class AbstractResultCachedefaultRule - default rule to setAbstractResultCache.setDefaultRule(ResultCacheRule)private CacheBehavior getCacheBehavior(SelectRequest request)
request - to get action for
CacheBehavior associated for this query.private java.lang.String getCacheKeyFromRequest(SelectRequest request)
request - the request to generate the key from
public boolean[] needInvalidate(ControllerResultSet result,
UpdateRequest request)
result - that could be in the cacherequest - the update we want to get updated values from
public void addToCache(SelectRequest request,
ControllerResultSet result)
throws CacheException
addToCache in class AbstractResultCacherequest - the requestresult - the result corresponding to the request
CacheException - if an error occursprotected abstract void processAddToCache(AbstractResultCacheEntry qe)
qe - to add to the cache.
public AbstractResultCacheEntry getFromCache(SelectRequest request,
boolean addToPendingQueries)
AbstractResultCacheEntry is null if the
request is not present in the cache.
An invalid AbstractResultCacheEntry may be returned (it
means that the result is null) but the already parsed query
can be retrieved from the cache entry.
getFromCache in class AbstractResultCacherequest - an SQL select requestaddToPendingQueries - true if the request must be added
to the pending query list on a cache miss
AbstractResultCacheEntry if found, else
nullpublic void removeFromCache(SelectRequest request)
removeFromCache in class AbstractResultCacherequest - a SelectRequestpublic void removeFromPendingQueries(SelectRequest request)
removeFromPendingQueries in class AbstractResultCacherequest - a SelectRequest
public abstract boolean isUpdateNecessary(UpdateRequest request)
throws CacheException
AbstractResultCache
isUpdateNecessary in class AbstractResultCacherequest - the update request that needs to be executed
CacheException - if an error occursAbstractResultCache.isUpdateNecessary(org.objectweb.cjdbc.common.sql.UpdateRequest)
public void writeNotify(AbstractWriteRequest request)
throws CacheException
writeNotify in class AbstractResultCacherequest - an AbstractRequest value
CacheException - if an error occursprotected abstract void processWriteNotify(AbstractWriteRequest request)
request - Write request that invalidates the cache.public void flushCache()
flushCache in class AbstractResultCachepublic long getCacheSize()
getCacheSize in class AbstractResultCacheprivate void removeOldest()
!Warning! This method is not synchronized and should be called in the scope of a synchronized(queries)
public int getParsingGranularity()
getParsingGranularity in class AbstractResultCacheAbstractResultCache.setParsingGranularity(int)public abstract java.lang.String getName()
public void commit(long transactionId)
throws CacheException
commit in class AbstractResultCachetransactionId - the transaction id
CacheException - if an error occurs
public void rollback(long transactionId)
throws CacheException
rollback in class AbstractResultCachetransactionId - the transaction id
CacheException - if an error occurs
public java.lang.String[][] getCacheData()
throws CacheException
AbstractResultCache
getCacheData in class AbstractResultCacheCacheException - if failsAbstractResultCache.getCacheData()
public java.lang.String[][] getCacheStatsData()
throws CacheException
AbstractResultCache
getCacheStatsData in class AbstractResultCacheCacheException - if fails to collect the data.AbstractResultCache.getCacheStatsData()public CacheStatistics getCacheStatistics()
AbstractResultCache
getCacheStatistics in class AbstractResultCachepublic java.util.ArrayList getEagerCache()
public java.util.ArrayList getRelaxedCache()
protected java.lang.String getXmlImpl()
getXmlImpl in class AbstractResultCacheString containing information
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||