builder: isolate all the cache handling to a new Cache module

While there is not that much in it, it groups together the small
scattered-around bits handling the cache directory.