Cache lookup code refactoring