cachetest: refactor file reading code to accept a cache-getting closure