doctor: check cache directory is writable.

Fixes #32304.
Fixes #34933.