In the current behavior on master, if invalid PNG data is downloaded via 200 / CURLE_OK that data is still written out to the filesystem. This should be changed so that PNG data is loaded to a surface (and freed) to ensure the downloaded data is a valid image / PNG.
Largely complete implementation on branch tile-caching-rework
.