Fixing cache function