DNA Cafe | Download | FreeSoftware | Java | Links

DNA - FreeSoftware - ccache

ccache is a compiler cache. It speeds up re-compilation of C/C++ code by caching previous compiles and detecting when the same compile is being done again.


How to use

There is just to prefix your compile commands with "ccache".

$ make CC="ccache cc"

You can change cc if you need. When the same compilation is done a second time ccache is able to supply the correct compiler output from the cache. For example,

$ make CC="ccache cc" # 1st time
$ make CC="ccache cc" clean
$ make CC="ccache cc" # 2nd time

Using ccache with distcc

You just set the environment variable CCACHE_PREFIX to "distcc".

$ make CCACHE_PREFIX="distcc" CC=ccache


cache management

These options only apply when you invoke ccache as "ccache".

Statistics summary:

$ ccache -s

To clean cache and re-calculate:

$ ccache -c

To clear the entire cache:

$ ccache -C

To management cache size:

$ ccache -F size -M number_of_files_limits

By default ccache has a one gibibyte limit on the cache size and no maximum number of files.


Sharing a cache directory

A group of developers can increase the cache hit rate by sharing a cache directory.

Sharing a cache directory on a host

To share a cache, the fllowing conditions need to be met:

  1. Create a new group account to share a cache, and modify a member of.
  2. Make sure that all users have write permission in the entire cache directory.
  3. Make sure that the setgid bit is set on all directories in the cache.

For example,

$ groupadd -g 1234 ccache
$ vigr

/etc/group
ccache:*:1234:user

$ mkdir common_directory
$ chgrp ccache common_directory
$ chmod g+s common_directory

Now, you can use it. Use the same CCACHE_DIR environment variable setting, and the CCACHE_UNMASK sets the umask to share cache with other users. The CCACHE_LOGFILE is useful for tracking down proglems.

$ CCACHE_DIR=common_directory
$ CCACHE_UNMASK=002
$ CCACHE_LOGFILE=logfile
$ export CCACHE_DIR CCACHE_UNMASK CCACHE_LOGFILE
$ make CC="ccache cc"

Sharing a cache directory for distributing compilation

distcc is a very useful program for distributing compilation across a range of compiler servers. It is often useful to combine distcc with ccache. To share a cache with distcc, the fllowing conditions need to be met:

  1. Create shared cache as above.
  2. Set distccd to use compiler servers.

You just need to set the environment variable CCACHE_PREFIX to 'distcc'.

$ export DISTCC_HOSTS="host_to_use_for_compilation ..."
$ export CCACHE_DIR=common_directory
$ export CCACHE_UMASK=002
$ export CCACHE_PREFIX=distcc
$ export CCACHE_LOGFILE=logfile
$ make -j4 CC="ccache cc"

Please refer to distcc note for the -j value.


Reference

http://ccache.samba.org/
ccache Home page
distcc.html
Note for distcc.

Vector Valid XHTML 1.1! Valid CSS!