Fix crash in ClearCache in some cases