Novak Djokovic says he “suffered a lot” during a hard-fought victory over fellow veteran Marin Cilic in the second round of the Shanghai Masters.