> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# query_cache_* session settings

> ClickHouse session settings in the query_cache_* generated group.

These settings are available in [system.settings](https://clickhouse.com/docs/reference/system-tables/settings.md) and are autogenerated from [source](https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/Settings.cpp).

## query\_cache\_compress\_entries

Type

Bool

Default

1

Compress entries in the [query cache](https://clickhouse.com/docs/concepts/features/performance/caches/query-cache.md). Lessens the memory consumption of the query cache at the cost of slower inserts into / reads from it.

Possible values:

* 0 - Disabled
* 1 - Enabled

## query\_cache\_for\_subqueries

Type

Bool

Default

0

If turned on, subquery results may be written to and read from the [query cache](https://clickhouse.com/docs/concepts/features/performance/caches/query-cache.md). This enables propagation of `use_query_cache` into all subqueries.

Possible values:

* 0 - Disabled
* 1 - Enabled

## query\_cache\_max\_entries

Type

UInt64

Default

0

The maximum number of query results the current user may store in the in-memory [query cache](https://clickhouse.com/docs/concepts/features/performance/caches/query-cache.md). 0 means unlimited.

This limit does not apply to the query cache on disk (setting `query_cache_on_disk_cache_name`), whose entries are bounded by the size of the underlying filesystem cache instead.

Possible values:

* Positive integer >= 0.

## query\_cache\_max\_size\_in\_bytes

Type

UInt64

Default

0

The maximum amount of memory (in bytes) the current user may allocate in the in-memory [query cache](https://clickhouse.com/docs/concepts/features/performance/caches/query-cache.md). 0 means unlimited.

This limit does not apply to the query cache on disk (setting `query_cache_on_disk_cache_name`), whose entries are bounded by the size of the underlying filesystem cache instead.

Possible values:

* Positive integer >= 0.

## query\_cache\_min\_query\_duration

Type

Milliseconds

Default

0

Minimum duration in milliseconds a query needs to run for its result to be stored in the [query cache](https://clickhouse.com/docs/concepts/features/performance/caches/query-cache.md).

Possible values:

* Positive integer >= 0.

## query\_cache\_min\_query\_runs

Type

UInt64

Default

0

Minimum number of times a `SELECT` query must run before its result is stored in the [query cache](https://clickhouse.com/docs/concepts/features/performance/caches/query-cache.md).

Possible values:

* Positive integer >= 0.

## query\_cache\_nondeterministic\_function\_handling

Type

QueryResultCacheNondeterministicFunctionHandling

Default

throw

Controls how the [query cache](https://clickhouse.com/docs/concepts/features/performance/caches/query-cache.md) handles `SELECT` queries with non-deterministic functions like `rand()` or `now()`.

Possible values:

* `'throw'` - Throw an exception and don't cache the query result.
* `'save'` - Cache the query result.
* `'ignore'` - Don't cache the query result and don't throw an exception.

## query\_cache\_on\_disk\_cache\_name

The name of a filesystem cache (an entry of the `filesystem_caches` section of the server configuration) which stores entries of the [query cache](https://clickhouse.com/docs/concepts/features/performance/caches/query-cache.md) on disk. If a name is given (and [use\_query\_cache](https://clickhouse.com/docs/reference/settings/session-settings/use-query.md#use_query_cache) is enabled), query results are additionally cached in (and served from) the specified filesystem cache. The on-disk query cache provides more space than the in-memory query cache, survives server restarts, and works independently of the in-memory query cache: settings [enable\_reads\_from\_query\_cache\_on\_disk](https://clickhouse.com/docs/reference/settings/session-settings/enable.md#enable_reads_from_query_cache_on_disk) and [enable\_writes\_to\_query\_cache\_on\_disk](https://clickhouse.com/docs/reference/settings/session-settings/enable.md#enable_writes_to_query_cache_on_disk) control it separately from the in-memory query cache. The entries in the filesystem cache are ordinary entries of the filesystem cache: they are not held from deletion and they are evicted by the same rules as any other data in it. `SYSTEM CLEAR FILESYSTEM CACHE '<name>'` removes them together with everything else in the filesystem cache, and `SYSTEM CLEAR QUERY CACHE` removes the entries of the query cache on disk from the filesystem cache named by this setting, leaving all other data in place. A dedicated filesystem cache for query results is recommended.

Possible values:

* Empty string - The query cache on disk is disabled
* The name of a preconfigured filesystem cache

## query\_cache\_on\_disk\_codec

Type

String

Default

ZSTD(3)

The compression codec for entries of the [query cache](https://clickhouse.com/docs/concepts/features/performance/caches/query-cache.md) on disk (see [query\_cache\_on\_disk\_cache\_name](https://clickhouse.com/docs/reference/settings/session-settings/query-cache.md#query_cache_on_disk_cache_name)). Only affects writing; reading is independent of this setting because the compressed data is self-describing.

## query\_cache\_share\_between\_users

Type

Bool

Default

0

If turned on, the result of `SELECT` queries cached in the [query cache](https://clickhouse.com/docs/concepts/features/performance/caches/query-cache.md) can be read by other users.
It is not recommended to enable this setting due to security reasons.

Possible values:

* 0 - Disabled
* 1 - Enabled

## query\_cache\_squash\_partial\_results

Type

Bool

Default

1

Squash partial result blocks to blocks of size [max\_block\_size](https://clickhouse.com/docs/reference/settings/session-settings/max.md#max_block_size). Reduces performance of inserts into the [query cache](https://clickhouse.com/docs/concepts/features/performance/caches/query-cache.md) but improves the compressibility of cache entries (see [query\_cache\_compress-entries](https://clickhouse.com/docs/reference/settings/session-settings/query-cache.md#query_cache_compress_entries)).

Possible values:

* 0 - Disabled
* 1 - Enabled

## query\_cache\_system\_table\_handling

Type

QueryResultCacheSystemTableHandling

Default

throw

Controls how the [query cache](https://clickhouse.com/docs/concepts/features/performance/caches/query-cache.md) handles `SELECT` queries against system tables, i.e. tables in databases `system.*` and `information_schema.*`.

Possible values:

* `'throw'` - Throw an exception and don't cache the query result.
* `'save'` - Cache the query result.
* `'ignore'` - Don't cache the query result and don't throw an exception.

## query\_cache\_tag

A string which acts as a label for [query cache](https://clickhouse.com/docs/concepts/features/performance/caches/query-cache.md) entries.
The same queries with different tags are considered different by the query cache.

Possible values:

* Any string

## query\_cache\_ttl

Type

Seconds

Default

60

After this time in seconds entries in the [query cache](https://clickhouse.com/docs/concepts/features/performance/caches/query-cache.md) become stale.

Possible values:

* Positive integer >= 0.
