Caching not working when using GCS as the backend

caching

#1

I have a static website that has GCS as the backend, but the caching is not working for images.

I have the domain “www.example.com” CNAMEd to “c.storages.googleapis.com” and has CDN proxy enabled (orange cloud icon). But the images are always a MISS (from the header)

curl -vso /dev/null https://www.traversal.in/assets/photography/roopkund/IMG_6717__489x326.jpg
*   Trying 104.27.176.2...
* Connected to www.traversal.in (104.27.176.2) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /usr/local/etc/openssl/cert.pem
  CApath: none
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
} [5 bytes data]
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
} [512 bytes data]
* TLSv1.2 (IN), TLS handshake, Server hello (2):
{ [96 bytes data]
* TLSv1.2 (IN), TLS handshake, Certificate (11):
{ [4852 bytes data]
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
{ [148 bytes data]
* TLSv1.2 (IN), TLS handshake, Server finished (14):
{ [4 bytes data]
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
} [70 bytes data]
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
} [1 bytes data]
* TLSv1.2 (OUT), TLS handshake, Finished (20):
} [16 bytes data]
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
{ [1 bytes data]
* TLSv1.2 (IN), TLS handshake, Finished (20):
{ [16 bytes data]
* SSL connection using TLSv1.2 / ECDHE-ECDSA-AES128-GCM-SHA256
* ALPN, server accepted to use h2
* Server certificate:
*  subject: OU=Domain Control Validated; OU=PositiveSSL Multi-Domain; CN=sni253260.cloudflaressl.com
*  start date: Jun  3 00:00:00 2018 GMT
*  expire date: Dec 10 23:59:59 2018 GMT
*  subjectAltName: host "www.traversal.in" matched cert's "*.traversal.in"
*  issuer: C=GB; ST=Greater Manchester; L=Salford; O=COMODO CA Limited; CN=COMODO ECC Domain Validation Secure Server CA 2
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* TCP_NODELAY set
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
} [5 bytes data]
* Using Stream ID: 1 (easy handle 0x7fcfc2008400)
} [5 bytes data]
> GET /assets/photography/roopkund/IMG_6717__489x326.jpg HTTP/1.1
> Host: www.traversal.in
> User-Agent: curl/7.50.0
> Accept: */*
>
{ [5 bytes data]
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
} [5 bytes data]
< HTTP/2 200
< date: Tue, 19 Jun 2018 11:21:32 GMT
< content-type: image/jpeg
< content-length: 94880
< set-cookie: __cfduid=d2fbfdc4db3b117bec4c58edffdbecff61529407292; expires=Wed, 19-Jun-19 11:21:32 GMT; path=/; domain=.traversal.in; HttpOnly
< x-guploader-uploadid: AEnB2UoB1QQatIW_yuiHIcwgCCZDU9rUbQd8cb9InqMtiQgGYpQbphckMpje2n4EDfCYnDjk-l6lk43WcrzHsndV3fzlDEHvqQ
< expires: Wed, 20 Jun 2018 11:21:32 GMT
< cache-control: public, max-age=86400
< last-modified: Mon, 21 May 2018 15:41:02 GMT
< etag: "4709827402cd3f10c633966128d5e8f3"
< x-goog-generation: 1526917262440017
< x-goog-metageneration: 1
< x-goog-stored-content-encoding: identity
< x-goog-stored-content-length: 94880
< x-goog-meta-goog-reserved-file-mtime: 1526046344
< content-language: en
< x-goog-hash: crc32c=I/QclA==
< x-goog-hash: md5=RwmCdALNPxDGM5ZhKNXo8w==
< x-goog-storage-class: REGIONAL
< accept-ranges: bytes
< alt-svc: quic=":443"; ma=2592000; v="43,42,41,39,35"
< cf-cache-status: MISS
< expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
< server: cloudflare
< cf-ray: 42d59cd81cb33114-SIN
<
{ [638 bytes data]
* Connection #0 to host www.traversal.in left intact

#2

The origin server is explicitly telling Cloudflare not to cache it.

curl -Ik https://c.storage.googleapis.com/assets/photography/roopkund/IMG_6717__489x326.jpg --header “Host:www.traversal.in”

HTTP/2 200
x-guploader-uploadid: AEnB2UqCimpb1NCTJcAoWZCxIEvW1RV6II75X25SPTq9Mz_x5NpjSZoTSCz0aT_fvcbPoinMZLA7UKO-Zr4gP5wTv79DiJON5Bq2DQH-LpXr6bhecSuAfk8
expires: Tue, 19 Jun 2018 14:46:52 GMT
date: Tue, 19 Jun 2018 14:46:52 GMT
cache-control: private, max-age=0


#3

OMG! Thank you so much. I just changed the metadata of all the files and it worked.
This is what I used
gsutil setmeta -r -h “Cache-Control: max-age=86400” “gs://bucket-name/*”


#4

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.