Restrict cache clear cases, refine cache ID, refactor #5396