public class OSQueryCache extends Object implements QueryCache
QueryCache
implementation based on OpenSymphony OSCache. Query cache
parameters are initialized from "/oscache.properties" file per OSCache
documentation. In addition to the standard OSCache parameters, Cayenne provider allows
to setup global cache expiration parameters, and parameters matching the main query
cache group (i.e. the cache groups specified first). A sample oscache.properties may
look like this:
# OSCache configuration file # OSCache standard configuration per # http://www.opensymphony.com/oscache/wiki/Configuration.html # --------------------------------------------------------------- #cache.memory=true #cache.blocking=false cache.capacity=5000 cache.algorithm=com.opensymphony.oscache.base.algorithm.LRUCache # Cayenne specific properties # --------------------------------------------------------------- # Default refresh period in seconds: cayenne.default.refresh = 60 # Default expiry specified as cron expressions per # http://www.opensymphony.com/oscache/wiki/Cron%20Expressions.html # expire entries every hour on the 10's minute cayenne.default.cron = 10 * * * * # Same parameters can be overriden per query cayenne.group.xyz.refresh = 120 cayenne.group.xyz.cron = 10 1 * * *Further extension of OSQueryCache is possible by using OSCache listener API.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_REFRESH_PERIOD |
protected com.opensymphony.oscache.general.GeneralCacheAdministrator |
osCache |
Constructor and Description |
---|
OSQueryCache() |
OSQueryCache(com.opensymphony.oscache.general.GeneralCacheAdministrator cache,
Properties properties) |
Modifier and Type | Method and Description |
---|---|
int |
capacity() |
void |
clear()
Clears all cache entries.
|
List |
get(QueryMetadata metadata)
Returns a cached query result for the given QueryMetadata or null if the result is
not cached or is expired.
|
List |
get(QueryMetadata metadata,
QueryCacheEntryFactory factory)
Returns a non-null cached value.
|
String |
getCronExpression(String groupName) |
Collection |
getGroupNames()
Returns a collection of group names that have been configured explicitly via
properties.
|
com.opensymphony.oscache.general.GeneralCacheAdministrator |
getOsCache()
Returns the underlying OSCache manager object.
|
Properties |
getProperties()
Returns configuration properties.
|
int |
getRrefreshPeriod(String groupName) |
protected void |
initCronPolicy(String groupName,
Object value)
Called internally for each group that is configured with cron policy in the
properties.
|
protected void |
initRefreshPolicy(String groupName,
Object value)
Called internally for each group that is configured with refresh policy in the
properties.
|
void |
put(QueryMetadata metadata,
List results) |
void |
remove(String key)
Removes a single entry from cache.
|
void |
removeGroup(String groupKey)
Removes a group of entries identified by group key.
|
void |
shutdown()
Shuts down EhCache CacheManager
|
int |
size()
Returns the number of entries currently in the cache, including expired but not
removed entries.
|
public static final int DEFAULT_REFRESH_PERIOD
protected com.opensymphony.oscache.general.GeneralCacheAdministrator osCache
public OSQueryCache()
public OSQueryCache(com.opensymphony.oscache.general.GeneralCacheAdministrator cache, Properties properties)
public Collection getGroupNames()
public int getRrefreshPeriod(String groupName)
public com.opensymphony.oscache.general.GeneralCacheAdministrator getOsCache()
public Properties getProperties()
protected void initCronPolicy(String groupName, Object value)
protected void initRefreshPolicy(String groupName, Object value)
public List get(QueryMetadata metadata)
QueryCache
get
in interface QueryCache
public List get(QueryMetadata metadata, QueryCacheEntryFactory factory)
QueryCacheEntryFactory.createObject()
. Whether the cache
provider will block on the entry update or not is controlled by "cache.blocking"
configuration property and is "false" by default.get
in interface QueryCache
public void put(QueryMetadata metadata, List results)
put
in interface QueryCache
public void remove(String key)
QueryCache
remove
in interface QueryCache
public void removeGroup(String groupKey)
QueryCache
removeGroup
in interface QueryCache
public void clear()
QueryCache
clear
in interface QueryCache
public int size()
QueryCache
size
in interface QueryCache
public int capacity()
@BeforeScopeEnd public void shutdown()
Copyright © 2001–2015 Apache Cayenne. All rights reserved.