Fix cache pruning.
Fix double close.