Refactor purge_cache