Purge image cache when needed to fix #4935