Refactoring cache computation