I\'m trying to inject data/response from URLRequest into another URLRequest in my cache.
This is just a sample code. It\'s re
This isn't a complete answer, but it should put you in the right direction.
The issue isn't to do with your code, I believe that it's mostly fine. The issue is regarding the response that you get from the landscapeURLString because the image is stored in Cloudflare. If you use 2 images from the same source, (e.g. try with this bear from wikipedia instead of the image from images.pexels.com) it should work.
I tried printing out the response and headers of downloading the images.pexels.com image and this is what I saw:
response: { URL: https://upload.wikimedia.org/wikipedia/commons/e/e0/Large_Scaled_Forest_Lizard.jpg } { Status Code: 200, Headers {
"Accept-Ranges" = (
bytes
);
"Cache-Control" = (
"public, max-age=31536000"
);
"Content-Length" = (
997361
);
"Content-Type" = (
"image/jpeg"
);
Date = (
"Wed, 31 Oct 2018 11:38:52 GMT"
);
Expires = (
"Thu, 31 Oct 2019 11:38:52 GMT"
);
"Last-Modified" = (
"Fri, 26 Oct 2018 6:31:56 GMT"
);
Server = (
cloudflare
);
Vary = (
"Accept-Encoding"
);
"cf-cache-status" = (
HIT
);
"cf-ray" = (
"4725d67b0ae461bd-BCN"
);
"expect-ct" = (
"max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\""
);
"x-cache" = (
"HIT, MISS"
);
"x-content-type-options" = (
nosniff
);
"x-served-by" = (
"cache-lax8643-LAX, cache-mad9437-MAD"
);
} }
headers: ["Accept-Ranges": "bytes", "Content-Type": "image/jpeg", "Last-Modified": "Fri, 26 Oct 2018 6:31:56 GMT", "Vary": "Accept-Encoding", "cf-ray": "4725d67b0ae461bd-BCN", "Date": "Wed, 31 Oct 2018 11:38:52 GMT", "Server": "cloudflare", "Expires": "Thu, 31 Oct 2019 11:38:52 GMT", "x-content-type-options": "nosniff", "expect-ct": "max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"", "x-cache": "HIT, MISS", "x-served-by": "cache-lax8643-LAX, cache-mad9437-MAD", "cf-cache-status": "HIT", "Content-Length": "997361", "Cache-Control": "public, max-age=31536000"]
There's probably something in there that is trying to match the request URL with a response field that's causing the cache miss, but I'm not knowledgable enough to know what it is. Somebody else can probably catch it for you (hence why I said that this answer is incomplete).