Closed andrewdmontgomery closed 5 months ago
You are suggesting this to avoid re-downloading the same image right?
Setting cache policy to reloadRevalidatingCacheData seems to be doing that already. https://stackoverflow.com/questions/72995149/urlsession-caching-not-working-as-documented-what-am-i-doing-wrong
So let's investigate that first.
This also made me realize, we should use "reloadIgnoringLocalCacheData" when the caller party passes "forceRefresh = true".
You are suggesting this to avoid re-downloading the same image right?
Yep. And yeah, that sounds like a good direction to try first.
This also made me realize, we should use "reloadIgnoringLocalCacheData" when the caller party passes "ignoreCache = true".
Good call
In the meantime I was checking what the default cache policy does:
It first checks the cached response to see if it is stale or requires revalidation. If yes, it makes a HEAD request to check if there's a new image on the server, only after that it fetches the image. I think it also depends on how much of these things our backend supports but the default cache policy looks also quite reasonable to me.
Doing a backlog cleanup and closing this for now. We can reopen it in the future if needed.
The existing image caching doesn't have a way to detect changes to the remote image. If the image is fetched and cached, and then subsequently updated through some other means (e.g. the web portal), this caching mechanism won't detect that.
The source of truth is the
Last-Modified
header in the response from the API when we fetch an avatar. We can use that. We should be able to add anIf-Modified-Since
header to our requests and then process the response accordingly:I believe this would just mean updating the
imageRequest(url:URL) -> URLRequest
function to set the right header:The response:
So we would:
In fact, we'd want to:
If-Modified-Since
header of the request