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.
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
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.
TODO
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: