Refactor cache function in WindowContext.