# Improving ccache Cache Hits



## poorandunlucky (Dec 20, 2017)

Is there a way to improve ccache's cache hit?

Here are my current stats:


```
[Wed Dec 20 2017 13:35:02.420] poorandunlucky@M6500 ~ > ccache -s
cache directory                     /var/db/ccache
primary config                      /var/db/ccache/ccache.conf
secondary config      (readonly)    /usr/local/etc/ccache.conf
cache hit (direct)                 10587
cache hit (preprocessed)            3800
cache miss                         99081
cache hit rate                     12.68 %
called for link                    19443
called for preprocessing            8003
multiple source files                  5
compile failed                      1496
preprocessor error                  1424
can't use precompiled header          20
bad compiler arguments               658
unsupported source language            7
autoconf compile/link               9022
unsupported compiler option          510
unsupported code directive             2
no input file                       4460
cleanups performed                     0
files in cache                    284040
cache size                           7.3 GB
max cache size                      15.0 GB
[Wed Dec 20 2017 13:35:06.146] poorandunlucky@M6500 ~ >
```

There's stuff in the man page about adding "fuzziness", something like fuzzy_ctime, etc, that I thought would improve cache hits, but it ended-up lowering it...

Now it's just basically the default config, here's my config file that has the "sloppiness" I meant... and also my headers because i'm awesome.


```
################################################################################
# DogeOS 0.0.1
# Local CCACHE Configuration File
# ------------------------------------------------------------------------------
# This file configures CCACHE, the compiler cache.
# ==============================================================================

# ==============================================================================
#           | This is CCACHE's local configuration file.  The default file is
# IMPORTANT | located at /usr/local/etc/ccache.conf, and this file's settings
#           | override those found in the default file.
# ==============================================================================

cache_dir = /var/db/ccache
max_size = 15.0G
log_file = /var/log/ccache.log
#tmp_dir = /tmp
#sloppiness = file_stat_matches,include_file_ctime,include_file_mtime

# ==============================================================================
# DogeOS 0.0.1 - Yoonix | poorandunlucky <poorandunlucky@boardermail.com>
################################################################################
```

What do you guys have?  Anything I could do better?

Also, for the record, I wanted to make something like that, but it involved changing the way make handles the port tree and the work directory...  I essentially wanted to make it so make and/or portsnap would compare the new distfiles's contents to what was already there, and just overwrite what had been changed...  I'm not sure if it would've been better than ccache or not...


----------



## chrbr (Dec 21, 2017)

Hello poorandunlucky,
I guess the cache is quite fresh because there are 7.3G in while 15G are possible. And there have been no clean ups. If the content is used more often the hit rate should increase significantly. By the way, with `ccache -s` while compiling you should see changes in the statistics.


----------



## poorandunlucky (Dec 21, 2017)

chrbr said:


> Hello poorandunlucky,
> I guess the cache is quite fresh because there are 7.3G in while 15G are possible. And there have been no clean ups. If the content is used more often the hit rate should increase significantly. By the way, with `ccache -s` while compiling you should see changes in the statistics.



It is fresh, I just built my software once with it, but some things I'm running for the second time, and I see cache misses going up, but not so much cache hits...  I was just wondering if I was doing it right...


----------



## fernandel (Jan 4, 2018)

poorandunlucky said:


> It is fresh, I just built my software once with it, but some things I'm running for the second time, and I see cache misses going up, but not so much cache hits...  I was just wondering if I was doing it right...


It is mine:

```
cache hit (direct)               1768227
cache hit (preprocessed)          223410
cache miss                        476738
cache hit rate                     80.69 %
....
....
max cache size                      35.0 GB
```


----------



## poorandunlucky (Jan 4, 2018)

fernandel said:


> It is mine:
> 
> ```
> cache hit (direct)               1768227
> ...




Yeah, mine's gone up...  Guess I just have to deal with it while the cache builds...


```
[Thu Jan  4 2018 01:26:43.004] doge@M6500 /home/poorandunlucky # ccache -s
cache directory                     /var/db/ccache
primary config                      /var/db/ccache/ccache.conf
secondary config      (readonly)    /usr/local/etc/ccache.conf
cache hit (direct)                 25260
cache hit (preprocessed)            4778
cache miss                        114561
cache hit rate                     20.77 %
called for link                    24963
called for preprocessing           10176
multiple source files                  7
compiler produced stdout               1
compile failed                      2022
preprocessor error                  1983
can't use precompiled header          37
bad compiler arguments               807
unsupported source language            7
autoconf compile/link              11572
unsupported compiler option          535
unsupported code directive             2
no input file                       5238
cleanups performed                     0
files in cache                    329143
cache size                           8.6 GB
max cache size                      15.0 GB
[Thu Jan  4 2018 01:27:32.130] doge@M6500 /home/poorandunlucky #
```


----------

