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 separatly.