Refactor spy for cache