Simplified cache file lookup a bit for counting & culling.
Added regression tests for possible dataloss scenarios.