Fix bug when clearing memory cache