Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.cayenne.cache
Class OSQueryCache

    java.lang.Object
      org.apache.cayenne.cache.OSQueryCache

All Implemented Interfaces:
  QueryCache

    public class OSQueryCache

extends Object
implements QueryCache

A `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 provdier 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.

Since:
  3.0

Field Summary
`static int` | `DEFAULT_REFRESH_PERIOD`
`protected com.opensymphony.oscache.general.GeneralCacheAdministrator` | `osCache`

Constructor Summary
`OSQueryCache()`
`OSQueryCache(com.opensymphony.oscache.general.GeneralCacheAdministrator cache, Properties properties)`

Method Summary
`int` | `capacity()`
`void` | `clear()` Clears all 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.
`int` | `size()`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### DEFAULT_REFRESH_PERIOD

    public static final int DEFAULT_REFRESH_PERIOD

See Also:
  Constant Field Values

### osCache

    protected com.opensymphony.oscache.general.GeneralCacheAdministrator osCache

Constructor Detail

### OSQueryCache

    public OSQueryCache()

### OSQueryCache

    public OSQueryCache(com.opensymphony.oscache.general.GeneralCacheAdministrator cache,
                        Properties properties)

Method Detail

### getGroupNames

    public Collection getGroupNames()

  Returns a collection of group names that have been configured explicitly via properties.

### getCronExpression

    public String getCronExpression(String groupName)

### getRrefreshPeriod

    public int getRrefreshPeriod(String groupName)

### getOsCache

    public com.opensymphony.oscache.general.GeneralCacheAdministrator getOsCache()

  Returns the underlying OSCache manager object.

### getProperties

    public Properties getProperties()

  Returns configuration properties. Usually this is the contents of "oscache.properties" file.

### initCronPolicy

    protected void initCronPolicy(String groupName,
                                  Object value)

  Called internally for each group that is configured with cron policy in the properties. Exposed mainly for the benefit of subclasses. When overriding, call 'super'.

### initRefreshPolicy

    protected void initRefreshPolicy(String groupName,
                                     Object value)

  Called internally for each group that is configured with refresh policy in the properties. Exposed mainly for the benefit of subclasses. When overriding, call 'super'.

### get

    public List get(QueryMetadata metadata)

  Description copied from interface: `QueryCache`
  Returns a cached query result for the given QueryMetadata or null if the result is not cached or is expired.

  Specified by:
    `get` in interface `QueryCache`

### get

    public List get(QueryMetadata metadata,
                    QueryCacheEntryFactory factory)

  Returns a non-null cached value. If it is not present in the cache, it is obtained by calling `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.

  Specified by:
    `get` in interface `QueryCache`

### put

    public void put(QueryMetadata metadata,
                    List results)

  Specified by:
    `put` in interface `QueryCache`

### remove

    public void remove(String key)

  Description copied from interface: `QueryCache`
  Removes a single entry from cache.

  Specified by:
    `remove` in interface `QueryCache`

### removeGroup

    public void removeGroup(String groupKey)

  Description copied from interface: `QueryCache`
  Removes a group of entries identified by group key. This may not be supported by the implementation.

  Specified by:
    `removeGroup` in interface `QueryCache`

### clear

    public void clear()

  Description copied from interface: `QueryCache`
  Clears all entries.

  Specified by:
    `clear` in interface `QueryCache`

### size

    public int size()

  Specified by:
    `size` in interface `QueryCache`

### capacity

    public int capacity()

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2008 Apache Cayenne. All Rights Reserved.