Skip to main content
Version: 5.0.0

Query Cache

Query caching is a crucial optimization technique for enhancing query performance. By leveraging various caching mechanisms, you can improve query performance at multiple levels, including process, node, and cross-node. For hit-model queries, caching is enabled by default, but to ensure data consistency, it is disabled by default when querying the data source directly. Note that system restart is required for any query cache configuration changes to take effect.

Caching Criteria

Kylin selectively caches query results to optimize performance while managing memory resources. By default, it only caches slow queries with suitable result sizes. The caching criteria are defined by the following parameters:

Conditions for Caching: A query must meet at least one of the following conditions (No.1, No.2, or No.3) and also satisfy the condition in No.4 to be eligible for caching.

NoPropertiesDescriptionDefaultDefault unit
1kylin.query.cache-threshold-durationQueries whose duration is above this value2000millisecond
2kylin.query.cache-threshold-scan-countQueries whose scan row count is above this value10240row
3kylin.query.cache-threshold-scan-bytesQueries whose scan bytes is above this value1048576byte
4kylin.query.large-query-thresholdQueries whose result set size is below this value1000000cell

Ehcache Cache

By default, Kylin utilizes Ehcache as the query cache at each node or process level. To customize the configuration, update the settings in $KYLIN_HOME/conf/kylin.properties within your Kylin installation directory.

You can configure Ehcache to control the query cache size and policy by modifying the following configuration item:

  • Replace the default query cache configuration
  • Control query cache size
  • Define cache policy
PropertiesDescriptionDefault
kylin.query.cache-enabledWhether to enable query cache. When this property is enabled, the following properties take effect.true
kylin.cache.configThe path to ehcache.xml. To replace the default query cache configuration file, you can create a new file xml, for exemple ekcache2.xml, in the directory ${KYLIN_HOME}/conf/, and modify the value of this configuration item: file://${KYLIN_HOME}/conf/ehcache2.xmlclasspath:ehcache.xml

For more Ehcache configuration items, please refer to the official website: Ehcache Documentation

Redis Cache

The default query cache in Kylin is process-level, which means it cannot be shared across different nodes or processes. This limitation can lead to inefficiencies in cluster deployment mode, where subsequent identical queries may be routed to different Kylin nodes and cannot leverage the cache from the initial query.

To overcome this limitation, you can configure a Redis cluster as a distributed cache, enabling cache sharing across all Kylin nodes. For optimal performance, we recommend using Redis 5.0 or 5.0.5.

PropertiesDescriptionDefaultOptions
kylin.cache.redis.enabledWhether to enable query cache by using Redis cluster.falsetrue
kylin.cache.redis.cluster-enabledWhether to enable Redis cluster mode.falsetrue
kylin.cache.redis.hostsRedis host. If you need to connect to a Redis cluster, please use comma to split the hosts, such as, kylin.cache.redis.hosts=localhost:6379,localhost:6380localhost:6379
kylin.cache.redis.expire-time-unitTime unit for cache period. EX means seconds and PX means milliseconds.EXPX
kylin.cache.redis.expire-timeValid cache period.86400
kylin.cache.redis.reconnection.enabledWhether to enable redis reconnection when cache degrades to ehcachetruefalse
kylin.cache.redis.reconnection.intervalAutomatic reconnection interval, in minutes60
kylin.cache.redis.passwordRedis password

**Limitation:**Due to metadata inconsistency between Query nodes and All/Job nodes, the redis cache swith kylin.cache.redis.enabled=true should be configured along with kylin.server.store-type=jdbc.

Caution

Redis passwords can be encrypted, please refer to: Use MySQL as Metastore