Skip Headers

# Configuring Cache Expiration at the Query Level

Previous

Next

You can configure a `ReadQuery` with a `CacheInvalidationPolicy`.

If you configure a query to cache results in its own internal cache (see "Caching Results in a ReadQuery"), the cache invalidation policy allows the cached query result set to expire, based on a time-to-live or daily-expiry. This invalidation time is calculated from the time of the query execution that cached the query result set for the specific set of query parameters.

Example: Configuring a CacheInvalidationPolicy on a ReadQuery for the Query's Internal Cache shows how to configure a `ReadQuery` so that a `TimeToLiveCacheInvalidationPolicy` is applied to all the objects returned by the query and cached in the query's internal cache.

Configuring a CacheInvalidationPolicy on a ReadQuery for the Query's Internal Cache

    // The TimeToLiveCacheInvalidationPolicy applies to all objects returned by the query and
    // cached in the query's internal cache
    readQuery.setQueryResultsCachePolicy(
        new QueryResultsCachePolicy(new TimeToLiveCacheInvalidationPolicy(1000))
    );

For more information, see "Cache Invalidation".