Set Maximum Cache Size using Ccache

Set Maximum Cache Size using Ccache

Ccache stores compiled objects and related metadata in a cache directory. Over time, the cache can become large, which might put pressure on the disk if not properly managed. To prevent the cache from consuming too much space, Ccache lets you define a maximum cache size. Once the cache reaches that limit, older files are automatically removed to make room for new ones. This tutorial explains how to set maximum cache size using Ccache.

To check the current cache limit configured on the system, we can run:

ccache -k max_size

Example result:

5.0 GiB

If you want to raise (or lower) this cache limit, use the --max-size (or its shorthand -M) option:

ccache --max-size 10GiB
ccache -M 10GiB

To verify the setting has been applied and stored in the configuration file, list the active options:

ccache -p

You should see a line similar to:

(/home/ubuntu/.config/ccache/ccache.conf) max_size = 10.0 GiB

This confirms that the maximum cache size has been updated. If you ever want to revert to the default behavior, open ccache.conf and remove the corresponding line.

Leave a Comment

Cancel reply

Your email address will not be published.