Enforce ordering in shutdown sequence.

Fix cache loading.
Fix cache trimming.