Fix bug in cache cleanup.