Clean up cache instead of obliterating it

This still needs fixing in order to do anything useful.