Skip Headers

# Configuring Cache Usage for In-Memory Queries

Previous

Next

You can configure in-memory query cache usage at the query level using `ReadObjectQuery` and `ReadAllQuery` methods:

- `checkCacheByPrimaryKey`: The default setting; if a read-object query contains an expression that compares at least the primary key, you can obtain a cache hit if you process the expression against the objects in memory.

- `checkCacheByExactPrimaryKey`: If a read-object query contains an expression where the primary key is the only comparison, you can obtain a cache hit if you process the expression against the object in memory.

- `checkCacheThenDatabase`: You can configure any read-object query to check the cache completely before you resort to accessing the database.

- `checkCacheOnly`: You can configure any read-all query to check only the parent session cache (not the unit of work cache) and return the result from the parent session cache without accessing the database.

- `conformResultsInUnitOfWork`: You can configure any read-object or read-all query within the context of a unit of work to conform the results with the changes to the object made within that unit of work. This includes new objects, deleted objects and changed objects. For more information and limitations on conforming, see "Using Conforming Queries and Descriptors".

Alternatively, you can configure cache usage using the `ObjectLevelReadQuery` method `setCacheUsage`, passing in the appropriate `ObjectLevelReadQuery` field: `CheckCacheByPrimaryKey`, `CheckCacheByExactPrimaryKey`, `CheckCacheThenDatabase`, `CheckCacheOnly`, `ConformResultsInUnitOfWork`, or `DoNotCheckCache`.