Refactor cache management