public abstract class AbstractCacheableDatasource extends AbstractDatasource
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.#getCacheKey(String, Object[], int, int, Sorting[], Map)
or by implementing a custom AbstractCacheableDatasource.DatasourceResultCacheKeyBase
or extending AbstractCacheableDatasource.DatasourceResultCacheKey
Modifier and Type | Class and Description |
---|---|
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.
|
Datasource.Sorting
Modifier and Type | Field and Description |
---|---|
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
|
SORTORDER_ASC, SORTORDER_DESC, SORTORDER_NONE
Constructor and Description |
---|
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)
|
Modifier and Type | Method and Description |
---|---|
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.
|
clone, getCount, getCount, getId, getResult, getResult, getResult, getResult, getResult, hasChanged, isValidAttribute, setId
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
createDatasourceFilter, getCount, getCount2, getHandlePool, getResult, getResult, hasChanged, setAttributeNames, setRuleTree
protected boolean cacheEnabled
protected static final String RESULTSCACHEREGION
protected static final String COUNTCACHEREGION
protected com.gentics.lib.log.NodeLogger logger
public AbstractCacheableDatasource(String id)
id
- datasource idpublic AbstractCacheableDatasource(String id, boolean cacheEnabled)
id
- datasource idcacheEnabled
- false if caching should be disabled.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
- cache keyprotected Integer getCachedCount(AbstractCacheableDatasource.DatasourceResultCacheKeyBase cacheKey)
cacheKey
- cache keyprotected 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.protected boolean putCachedCount(AbstractCacheableDatasource.DatasourceResultCacheKeyBase cacheKey, Integer count)
cacheKey
- cache keycount
- count to be cachedgetCachedCount(com.gentics.api.lib.datasource.AbstractCacheableDatasource.DatasourceResultCacheKeyBase)
protected boolean clearCache()
protected String getUniqueDatasourceIdentifier()
getDatasourceIdentifier()
with
the class name.public String getDatasourceIdentifier()
Copyright © 2017 Gentics Software. All Rights Reserved.