Refactoring cache lookup and object query