refactor cache handling