cache_on_write_operations the filesystem cache acts as a write-through cache. Newly written data will automatically be cached in the filesystem cache.
Background merges can be further tweaked with the filesystem_cache_skip_download_if_exceeds_per_query_cache_write_limit & filesystem_cache_max_download_size settings.
As merges cause both a read and write of data (reading the to-be merged parts, combining them into a single part), merges can quickly pollute the cache with data. By tweaking the settings
above, you can control how much data can be loaded into the cache by a single query.
By default the filesystem cache uses an LRU (Least Recently Used) eviction strategy. ClickHouse also supports SLRU (segmented LRU), which protects frequently-used entries from being evicted by a single large scan
The filesystem cache sits between Object Storage and the query (see the hierarchy below), unless specifically bypassed with per-query settings such as enable_filesystem_cache.
- Hiding Latency from Object Storage. A round trip to Object Storage could take tens of milliseconds, whereas NVMe disk latency is measured in microseconds.
- Reduce Costs & prevent Throttling. Object Storage often charges per GET request. Hitting the filesystem cache prevents a GET request, thereby reducing the costs. It also prevents many GET requests from triggering throttling on the Object Storage.