|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.gentics.api.lib.datasource.AbstractDatasource
com.gentics.api.lib.datasource.AbstractCacheableDatasource
public abstract class AbstractCacheableDatasource
A abstract datasource which should make it easy to implement caching
for subclasses.
Implementors can use setCacheEnabled(boolean)
to
enable/disable the cache (by default it is enabled).
Before calling to the underlying storage engine, call
getCachedResult(DatasourceResultCacheKeyBase)
to retrieve
a cached result, and afterwards putCachedResult(DatasourceResultCacheKeyBase, Collection)
to put a newly retrieved result into the cache.
A cache key can either be retrieved using
#getCacheKey(String, Object[], int, int, Sorting[], Map)
or by implementing a custom {@link DatasourceResultCacheKeyBase}
or extending {@link DatasourceResultCacheKey}
Nested Class Summary | |
---|---|
static class |
AbstractCacheableDatasource.DatasourceCountCacheKey
Datasource cache key for count statements. |
static class |
AbstractCacheableDatasource.DatasourceResultCacheKey
A simple cache key used for caching datasource results. |
static interface |
AbstractCacheableDatasource.DatasourceResultCacheKeyBase
Interface used for uniquely identifying a DatasourceResult. |
Nested classes/interfaces inherited from interface com.gentics.api.lib.datasource.Datasource |
---|
Datasource.Sorting |
Field Summary | |
---|---|
protected boolean |
cacheEnabled
Defines if the cache is enabled for this instance. |
protected static String |
COUNTCACHEREGION
name of the cacheregion for count results |
protected com.gentics.lib.log.NodeLogger |
logger
|
protected static String |
RESULTSCACHEREGION
Name of the cacheregion for queryresults |
Fields inherited from interface com.gentics.api.lib.datasource.Datasource |
---|
SORTORDER_ASC, SORTORDER_DESC, SORTORDER_NONE |
Constructor Summary | |
---|---|
AbstractCacheableDatasource(String id)
Default constructor which will by default enable caching. |
|
AbstractCacheableDatasource(String id,
boolean cacheEnabled)
This constructor can be used if cache should not be used (by default the cache is enabled) |
Method Summary | |
---|---|
protected boolean |
clearCache()
Clears the cache for this datasource. |
protected Integer |
getCachedCount(AbstractCacheableDatasource.DatasourceResultCacheKeyBase cacheKey)
Returns the cached count for the given cache key or null if none was cached. |
protected Collection |
getCachedResult(AbstractCacheableDatasource.DatasourceResultCacheKeyBase cacheKey)
Returns the cached results of a query. |
protected AbstractCacheableDatasource.DatasourceResultCacheKeyBase |
getCacheKey(String query,
Object[] objects,
int start,
int count,
Datasource.Sorting[] sortedColumns,
Map specificParameters)
Creates and returns the cache key for the given parameters. |
protected AbstractCacheableDatasource.DatasourceResultCacheKeyBase |
getCacheKeyForCount(String query,
Object[] objects,
Map specificParameters)
Creates and returns a new cache key for a count statement. |
protected PortalCache |
getCountResultsCache()
|
String |
getDatasourceIdentifier()
Returns a unique identifier for this datasource. |
protected PortalCache |
getQueryResultsCache()
Returns the Query Results Cache. |
protected String |
getUniqueDatasourceIdentifier()
Returns a unique datasource identifier. |
boolean |
isCacheEnabled()
Returns if the cache is enabled. |
protected boolean |
putCachedCount(AbstractCacheableDatasource.DatasourceResultCacheKeyBase cacheKey,
Integer count)
Put a result of a getCount() method into the cache |
protected boolean |
putCachedResult(AbstractCacheableDatasource.DatasourceResultCacheKeyBase cacheKey,
Collection result)
Stores the given result collection into the cache for later retrieval. |
protected void |
setCacheEnabled(boolean cacheEnabled)
Sets if the cache should be enabled or disabled. |
Methods inherited from class com.gentics.api.lib.datasource.AbstractDatasource |
---|
clone, getCount, getCount, getId, getResult, getResult, getResult, getResult, getResult, hasChanged, isValidAttribute, setId |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.gentics.api.lib.datasource.Datasource |
---|
createDatasourceFilter, getCount, getCount2, getHandlePool, getResult, getResult, hasChanged, setAttributeNames, setRuleTree |
Field Detail |
---|
protected boolean cacheEnabled
protected static final String RESULTSCACHEREGION
protected static final String COUNTCACHEREGION
protected com.gentics.lib.log.NodeLogger logger
Constructor Detail |
---|
public AbstractCacheableDatasource(String id)
public AbstractCacheableDatasource(String id, boolean cacheEnabled)
cacheEnabled
- false if caching should be disabled.Method Detail |
---|
protected void setCacheEnabled(boolean cacheEnabled)
cacheEnabled
- true if cache should be enabled / false otherwise.public boolean isCacheEnabled()
protected AbstractCacheableDatasource.DatasourceResultCacheKeyBase getCacheKey(String query, Object[] objects, int start, int count, Datasource.Sorting[] sortedColumns, Map specificParameters)
Datasource.getResult(DatasourceFilter, String[], int, int, Sorting[], Map)
.
The only exception beeing query and objects. Except 'query' all parameters are optional and may be null.
query
- The Datasource / database specific query (e.g. for a datasource relying on a SQL database this would be the SQL query). Must not be null.objects
- The Datasource / database specific Objects which are referenced from the query (e.g. for a datasource relying on a SQL database this would be the variables binded in the SQL query)start
- The index of the first item which was returnedcount
- the nubmer of items in this resultsortedColumns
- the sort order of the resultspecificParameters
- additional parameters given to getResult(..) method.
NullPointerException
- if query is null.protected AbstractCacheableDatasource.DatasourceResultCacheKeyBase getCacheKeyForCount(String query, Object[] objects, Map specificParameters)
query
- datasource specific queryobjects
- datasource specific objects which are references from the query (e.g. bind variables)specificParameters
- additional parameters given to getCount(..) method.
NullPointerException
- if query is null.protected PortalCache getQueryResultsCache()
protected PortalCache getCountResultsCache()
protected Collection getCachedResult(AbstractCacheableDatasource.DatasourceResultCacheKeyBase cacheKey)
cacheKey
-
protected Integer getCachedCount(AbstractCacheableDatasource.DatasourceResultCacheKeyBase cacheKey)
protected boolean putCachedResult(AbstractCacheableDatasource.DatasourceResultCacheKeyBase cacheKey, Collection result)
cacheKey
- the cache to to uniquely identify the given resultresult
- the result which was produced with the cacheKey.
PortalCacheException
- if an error happened during caching the
result.protected boolean putCachedCount(AbstractCacheableDatasource.DatasourceResultCacheKeyBase cacheKey, Integer count)
getCachedCount(com.gentics.api.lib.datasource.AbstractCacheableDatasource.DatasourceResultCacheKeyBase)
protected boolean clearCache()
protected String getUniqueDatasourceIdentifier()
getDatasourceIdentifier()
with
the class name.
public String getDatasourceIdentifier()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |