Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is it not using cache? #416

Open
muxa opened this issue Jun 4, 2024 · 4 comments
Open

Why is it not using cache? #416

muxa opened this issue Jun 4, 2024 · 4 comments

Comments

@muxa
Copy link

muxa commented Jun 4, 2024

I've configureD imageproxy WITH with caching to disk:

/app/imageproxy -addr 0.0.0.0:8088 -cache /tmp/imageproxy -verbose

When I request the image, it's downloaded, stored on disk, resized and the resized image is also stored on disk (I can see the files in the data folder).

However in the logs I see that cache was not used when I request the same image again. Note that the image url I'm requesting contains query string parameters.

imageproxy listening on 0.0.0.0:8088
2024/06/04 09:25:52 fetching remote URL: https://REDACTED/index.php?gf-download=2024%2F06%2Fimage123.jpg&form-id=47&field-id=7&hash=0afa966d17976e112816ada2cc6b9275
2024/06/04 09:25:56 request: {Method:GET URL:https://REDACTED/index.php?gf-download=2024%2F06%2Fimage123.jpg&form-id=47&field-id=7&hash=0afa966d17976e112816ada2cc6b9275#1000x0 Proto:HTTP/1.1 ProtoMajor:1 ProtoMinor:1 Header:map[Accept:[image/*] User-Agent:[willnorris/imageproxy]] Body:<nil> GetBody:<nil> ContentLength:0 TransferEncoding:[] Close:false Host:REDACTED Form:map[] PostForm:map[] MultipartForm:<nil> Trailer:map[] RemoteAddr: RequestURI: TLS:<nil> Cancel:<nil> Response:<nil> ctx:0xc000038020} (served from cache: false)
2024/06/04 09:25:58 fetching remote URL: https://REDACTED/index.php?gf-download=2024%2F06%2Fimage123.jpg&form-id=47&field-id=7&hash=0afa966d17976e112816ada2cc6b9275
2024/06/04 09:26:01 request: {Method:GET URL:https://REDACTED/index.php?gf-download=2024%2F06%2Fimage123.jpg&form-id=47&field-id=7&hash=0afa966d17976e112816ada2cc6b9275#1000x0 Proto:HTTP/1.1 ProtoMajor:1 ProtoMinor:1 Header:map[Accept:[image/*] User-Agent:[willnorris/imageproxy]] Body:<nil> GetBody:<nil> ContentLength:0 TransferEncoding:[] Close:false Host:REDACTED Form:map[] PostForm:map[] MultipartForm:<nil> Trailer:map[] RemoteAddr: RequestURI: TLS:<nil> Cancel:<nil> Response:<nil> ctx:0xc000038020} (served from cache: false)
@tanrax
Copy link

tanrax commented Sep 6, 2024

Same problem with Redis connection

imageproxy -addr 0.0.0.0:8080 -cache redis://:@redis:6379/0 

@willnorris
Copy link
Owner

what caching headers is the upstream server sending? It's been a little while, but there was some discussion some time ago about overriding upstream caching headers, but I don't think it was ever implemented: #28

@tanrax
Copy link

tanrax commented Sep 8, 2024

Hi @willnorris

        proxy_set_header Connection "upgrade";
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host $server_name;
        proxy_set_header X-Real-IP $remote_addr;

However, the thumbnails are not in the folder. The CPU is always running. Imageproxy performs the resize but never saves the output.

@willnorris
Copy link
Owner

But what headers are sent from the server hosting the image? For example, the codercat image from GitHub specifies an etag, an expires timestamp, and a cache-control header:

% curl -I https://octodex.github.com/images/codercat.jpg
HTTP/2 200 
etag: "64f0b60d-70bf"
expires: Sun, 08 Sep 2024 16:54:00 GMT
cache-control: max-age=600

Those are what allow imageproxy to know how long it can cache the image. What happens if you try to load the codercat image in your proxy? Is it being served from cache? If so, then take a look at the response headers from the remote image you are loading to see if it has similar caching headers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants