Refactor to pull out cache specific code into a single function