Cayenne User Documentation
Caching and Fresh Data

## What Is Cached in Cayenne

Cayenne uses multiple levels of cache to significantly improve performance by reducing the number of trips to the database. Cayenne caches individual objects, reducing the need to fetch them from the database. It also is able to cache query results, that is, the information about which objects were retrieved by a particular query.

## Object cache

Individual objects are cached by Cayenne by default as they are fetched from the database or created by the user. Such caching is both a performance optimization mechanism and a way to ensure internal object uniquing. Users normally do not need to do anything special for this to work.

TODO

## Query cache

The query cache stores the result of a Query (SelectQuery, SqlTemplate or ProcedureQuery). The cached results are lists of objects. The cached list is matched to a query using a unique key internally generated by Cayenne for each query. Please mind that the query cache does not automatically refresh when committing changes, so if you query for all Artists starting with 'B', create a new artist 'Bob' and commit them, perform the same query again without refreshing the cache, then 'Bob' will not be found since the earlier cached query will be returned.

### Refreshing query cache

TODO

## Pluggable Cache

Third party caching providers can be used with Cayenne to provide more flexible caching options. Out of the box Cayenne provides two implementations of the pluggable cache factory:

- `'org.apache.cayenne.cache.MapQueryCacheFactory'` is a default factory that uses an LRU map to store query results. LRU map ensures that cached results would not take up all available memory, but otherwise it has no cache expiration mechanism.

- `'org.apache.cayenne.cache.OSQueryCacheFactory'` is a factory that installs OpenSymphony OSCache as a cache provider for Cayenne queries. It allows to configure cache expiration policies and cross-VM synchronization via an `"oscache.properties"` that should be placed in the CLASSPATH.

### Sections

1. RefreshQuery
2. Object Caching

.
Copyright ©2001-2008 Apache Software Foundation