cache.js: preparation for git module (factor out getCacheStat)

This is one of the first steps to factor out the git part of
`cache.js` into a separate module which can be tested separately.