cleanup: refactor cleanup_cache