All query caches have a pair of parameters that control the way individual queries interact with the cache:
- to instruct queries to use the cache for results.
The separation of concerns, usage and population, lets you include cached results for queries on uncommon data without polluting the cache with results that are unlikely to be reused by other queries, for example, large reports or queries on very old data.
To use caching, it must be enabled in the settings for the service to perform caching in the service’s runtime properties. By default, per-segment cache is enabled on Historicals. For individual queries, you can control cache usage and population within the query context.
Historicals only support segment-level caching, which is enabled by default. To control caching on the Historical, set the useCache
and populateCache
runtime properties. For example, to set the Historical to both use and populate the segment cache for queries:
Task executor services, the Peon or the Indexer, only support segment-level caching. To control caching on a task executor service, set the and populateCache
runtime properties. For example, to set the Peon to both use and populate the segment cache for queries:
See Peon caching and for a description of all available task executor service caching options.
Brokers support both segment-level and whole-query result level caching.
To control segment caching on the Broker, set the useCache
and populateCache
runtime properties. For example, to set the Broker to use and populate the segment cache for queries:
See Broker caching for a description of all available Broker cache configurations.
As long as the service is set to populate the cache, you can set cache options for individual queries in the query . For example, you can POST
a Druid SQL request to the HTTP POST API and include the context as a JSON object:
In this example the user has set populateCache
to to avoid filling the result cache with results for segments that are over a year old. For more information, see Druid SQL client APIs.
See the following topics for more information:
- for an overview of caching.
- Query context for more details and usage for the query context.