Skip Headers

# Using In-Memory Queries

Previous

Next

An in-memory query is a query that is run against the shared session cache. Careful configuration of in-memory querying improves performance, but not all queries benefit from in-memory querying. For example, queries for individual objects based on primary keys generally see performance gains from in-memory querying; queries not based on primary keys are less likely to benefit.By default, queries that look for a single object based on primary keys attempt to retrieve the required object from the cache first, and then to search the database if the object is not in the cache. All other query types search the database first, by default. You can specify whether a given query runs against the in-memory cache, the database, or both. In-memory querying lets you perform queries on the cache rather than the database. In-memory querying supports the following relationships:

- One-to-one

- One-to-many

- Many-to-many

- Aggregate collection

- Direct collection

  Note: By default, the relationships themselves must be in memory for in-memory traversal to work. Ensure that you trigger all value holders to enable in-memory querying to work across relationships.

This section describes the following:

- Configuring Cache Usage for In-Memory Queries

- Expression Options for In-Memory Queries

- Handling Exceptions Resulting From In-Memory Queries