Skip to content

AxonOps — AI-Native Control Plane for Open Source Data Platforms

nodetool setcachekeystosave

Sets the number of cache keys to save to disk for faster restart warmup.


Terminal window
nodetool [connection_options] setcachekeystosave <key_cache_keys> <row_cache_keys> <counter_cache_keys>

See connection options for connection options.

nodetool setcachekeystosave controls how many keys from each cache type are persisted to disk. These saved cache entries are loaded on node startup, allowing Cassandra to "warm" its caches without waiting for production traffic to populate them.

When a Cassandra node restarts, all in-memory caches are empty. Without saved caches, the node experiences a "cold start" period where:

  • Every read requires disk I/O to locate partition keys (no key cache)
  • Every read requires full SSTable scans (no row cache)
  • Counter operations require read-before-write from disk (no counter cache)

By saving cache entries to disk, Cassandra can restore hot cache entries on startup, significantly reducing the performance impact of restarts.

Cache Persistence LifecycleCache Persistence LifecycleRUNTIMEDISKSTARTUPKey Cache(in memory)Row Cache(in memory)Counter Cache(in memory)saved_caches/KeyCache-*.dbRowCache-*.dbCounterCache-*.dbKey Cache(warm)Row Cache(warm)Counter Cache(warm)Location: /var/lib/cassandra/saved_caches/Save triggers:• Periodic (key_cache_save_period)• Graceful shutdown (nodetool drain)Save N keys(periodic or shutdown)Load on restart(cache warming)

Caches are saved:

  • Periodically (controlled by *_cache_save_period in cassandra.yaml)
  • During graceful shutdown (nodetool drain)

Saved cache files are stored in /var/lib/cassandra/saved_caches/ (configurable via saved_caches_directory).


ArgumentDescriptionDefault Behavior
key_cache_keysMaximum keys to save from key cache0 = save all keys
row_cache_keysMaximum keys to save from row cache0 = save all keys
counter_cache_keysMaximum keys to save from counter cache0 = save all keys

Value of 0

Setting a value to 0 means "save all keys" (no limit), not "save nothing". To disable saving entirely, set the corresponding *_cache_save_period to 0 in cassandra.yaml.


For nodes with very large caches (multiple GB), saving all keys can slow down both the save operation and startup loading. Limiting the number of saved keys focuses on the most valuable entries:

Terminal window
# Save top 100,000 key cache entries, skip row cache, save 50,000 counter entries
nodetool setcachekeystosave 100000 0 50000

Control Disk Usage in saved_caches Directory

Section titled “Control Disk Usage in saved_caches Directory”

Saved cache files can grow large. Limiting keys reduces disk space:

Terminal window
# Check current saved cache sizes
du -sh /var/lib/cassandra/saved_caches/*
# Limit to reduce disk usage
nodetool setcachekeystosave 50000 0 10000

Row cache entries are large (full partition data). Saving them is expensive:

Terminal window
# Save key cache and counter cache, skip row cache entirely
nodetool setcachekeystosave 100000 0 50000

Row Cache Saving

Row cache saving is "much more expensive and has limited use" according to Cassandra documentation. The default save period for row cache is 0 (disabled). Only enable if specific use case requires it.


Keys SavedStartup Behavior
0 (all keys)Longer startup, but fully warm cache
Limited (e.g., 100K)Faster startup, partially warm cache
Very lowFast startup, mostly cold cache
Keys to SaveSave DurationDisk I/OFile Size
All keys (large cache)MinutesHighLarge (GB)
Limited keysSecondsLowSmall (MB)

If the value exceeds the actual cache size, Cassandra simply saves all available keys—no harm done. The setting is a maximum, not a requirement.

Cache TypeImpact of Low Value
Key CacheMore partition index disk reads on startup
Row CacheMore full disk reads for uncached partitions
Counter CacheMore read-before-write operations for counters

The cache will warm up over time from production traffic, but the initial post-restart period will have degraded performance.


Terminal window
nodetool setcachekeystosave 0 0 0
Terminal window
# Balance between startup speed and cache warmth
nodetool setcachekeystosave 100000 0 50000

Minimal Startup Time (Cold Start Acceptable)

Section titled “Minimal Startup Time (Cold Start Acceptable)”
Terminal window
# Skip all cache loading for fastest restart
nodetool setcachekeystosave 1 0 1

There is no direct command to view current keys-to-save settings. Check cassandra.yaml for persistent configuration:

Terminal window
grep -E "cache_keys_to_save" /etc/cassandra/cassandra.yaml

AspectBehavior
Runtime changeTakes effect immediately for next save operation
Across restartsNot persisted - reverts to cassandra.yaml values
Cluster scopePer-node setting - must run on each node

Edit cassandra.yaml:

# Number of keys to save (0 = all, default is disabled meaning all)
key_cache_keys_to_save: 100000
row_cache_keys_to_save: 0
counter_cache_keys_to_save: 50000
# How often to save (seconds)
key_cache_save_period: 14400 # 4 hours (default)
row_cache_save_period: 0 # disabled (default)
counter_cache_save_period: 7200 # 2 hours (default)

SettingControlsCommand
Cache capacity (size in MB)How much data can be cached in memorynodetool setcachecapacity
Keys to saveHow many entries are persisted to disknodetool setcachekeystosave
Save periodHow often caches are saved (cassandra.yaml only)N/A
Invalidate cacheClear cache contents immediatelynodetool invalidate*cache

Recommendations

  1. Key cache: Save a reasonable subset (100K-500K) rather than millions of entries
  2. Row cache: Keep at 0 unless explicitly using row caching (disabled by default)
  3. Counter cache: Save proportional to counter usage in workload
  4. Test startup time: Measure restart duration with different settings
  5. Monitor cache hit rates: Use nodetool info after restart to verify warmth

Key Cache Efficiency

Key cache is small relative to its benefit—each hit saves at least one disk seek. Saving 100,000 key cache entries typically takes only a few MB of disk space but can save thousands of disk seeks on startup.


CommandRelationship
setcachecapacitySet maximum cache sizes in memory
invalidatekeycacheClear key cache
invalidaterowcacheClear row cache
invalidatecountercacheClear counter cache
infoView cache statistics and hit rates
drainGraceful shutdown (triggers cache save)
# cassandra.yaml cache persistence settings
saved_caches_directory: /var/lib/cassandra/saved_caches
key_cache_save_period: 14400 # seconds between saves
key_cache_keys_to_save: 100000 # max keys to save
row_cache_save_period: 0 # disabled by default
row_cache_keys_to_save: 0 # all keys if enabled
counter_cache_save_period: 7200 # seconds between saves
counter_cache_keys_to_save: 50000 # max keys to save