Fixed Image Proxy refresh seems inefficient


Well-known member
Affected version
When refreshing a proxied image, XF\Service\ImageProxy::finalizeFromFetchResults() always does write the image file on success even if nothing has changed.

This does seem inefficient as it does cause more writes than necessary which could be an issue when using short refresh times and SSDs.

The file should therefore only be written if the data actually has changed, ideally by using a hash stored in the DB.
Probably better approach:
Use header If-Modified-Since when fetching the image.
This way (assuming servers do behave properly) the image does not even have to be re-downloaded if nothing has changed.

Unfortunately the header options are somewhat deep inside method \XF\Service\ImageProxy::fetchImageDataFromUrl(), so doing this via class extension requires duplicating code :(
Conclusion after test this in production for a few weeks:
Just relying on If-Modified-Since is not enough, there seem to be waay too many servers that apparently do not support this - we've therefore also implemented a hash check afterwards.

With those two approaches combined we were able to reduce our daily disk writes by about 70%, which I think is really worth the effort :)
Last edited:
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.2.8).

Change log:
Record image proxy file hashes, and do not overwrite files if their hashes have not changed
There may be a delay before changes are rolled out to the XenForo Community.
Top Bottom