Google Cloud CDN - Cache hit Issue

896 views
Skip to first unread message

Peter Ho

unread,
Jul 20, 2019, 3:52:46 PM7/20/19
to gce-discussion
Dear All,

It seem I have successfully setup the Load Balancing & Cloud CDN in GCP.
My website : https://united-athle.hk/

I have run the following command and it seem the CDN is working. But keep running this command WON'T return Age: value. Does it mean CACHE not work?!

Kas-MacBook-Pro:~ xxx$ HTTP/1.1 200 OK
Date: Sat, 20 Jul 2019 06:26:36 GMT
Server: Apache
Upgrade: h2,h2c
Last-Modified: Wed, 22 May 2019 01:04:31 GMT
Accept-Ranges: bytes
Content-Length: 47558
Vary: Accept-Encoding,User-Agent
Access-Control-Allow-Origin: *
Content-Type: text/css
Via: 1.1 google
Alt-Svc: clear
Connection: Upgrade

This is the load balancing report and seem not Cache hit activity. Any recommendation/idea?

load-balacing-details.png


Fady (Google Cloud Platform)

unread,
Jul 21, 2019, 12:11:58 AM7/21/19
to gce-discussion

The response seems to include all the required headers per this document. On the other hand, and per this header “ Access-Control-Allow-Origin:”, you are using cross-origin resource sharing (CORS). If you have not configured it on Google Cloud Storage as instructed in this document, it could be the reason it is not caching. One other possibility, and since you are using a query in the URL, you may have customized Cache Keys by excluding a component and as explained in these documents [1] [2]. You my also try to invalidate Cache as it seems that your max-age is set to a year and maybe reducing max-age to an hour (3600) as to debug may help.


For further help, and since it is a technical query, I suggest posting your question on serverfault.com. Please include the CORS policy, and explain your use-case as to help the community debug. I hope the above helps.


Peter Ho

unread,
Jul 22, 2019, 2:28:19 PM7/22/19
to gce-discussion
HI Fady,

Thank you for your reply.
For header “ Access-Control-Allow-Origin:”, I am not using Google Cloud Storage instead I used Instance group of VM. It seem ONLY Access-Control-Allow-Origin:”'s setting works. But I will try another way to test it. Also will try your suggestion to fix the issue. Thank you.

Peter

Peter Ho

unread,
Jul 22, 2019, 2:28:50 PM7/22/19
to gce-discussion
Just update the server setting fix "Cache-Control: max-age=31536000, public" header. But it seem the result is the same. Also provide GCP Log view details and not cache hit too

Kas-MacBook-Pro:~ billson$ HTTP/1.1 200 OK
Date: Sat, 20 Jul 2019 07:09:04 GMT
Server: Apache
Vary: X-Forwarded-Proto,Accept-Encoding,User-Agent

Upgrade: h2,h2c
Last-Modified: Wed, 22 May 2019 01:04:31 GMT
ETag: "b9c6-5896f8c4fb8fd"
Accept-Ranges: bytes
Content-Length: 47558
Cache-Control: max-age=31536000, public
Expires: Sun, 19 Jul 2020 07:09:04 GMT
Referrer-Policy: no-referrer-when-downgrade
Access-Control-Allow-Origin: *
Pragma: public

Content-Type: text/css
Via: 1.1 google
Alt-Svc: clear
Connection: Upgrade

GCP Log viewer:
{
 httpRequest: {
  cacheFillBytes:  "28807"   
  cacheLookup:  true   
  referer:  "https://united-athle.hk/"   
  remoteIp:  "58.176.86.205"   
  requestMethod:  "GET"   
  requestSize:  "265"   
  requestUrl:  "https://cdn.ua.sugarproject.com/wp-includes/css/dashicons.min.css?x42707&ver=5.2.2"   
  responseSize:  "28807"   
  serverIp:  "10.170.0.2"   
  status:  200   
  userAgent:  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36"   
 }
 insertId:  "bo55k4g4dvcs95"  
 jsonPayload: {
  @type:  "type.googleapis.com/google.cloud.loadbalancing.type.LoadBalancerLogEntry"   
  statusDetails:  "response_sent_by_backend"   
 }
 logName:  "projects/calm-seeker-170606/logs/requests"  
 receiveTimestamp:  "2019-07-20T07:07:58.472254899Z"  
 resource: {
  labels: {…}   
  type:  "http_load_balancer"   
 }
 severity:  "INFO"  
 spanId:  "afaa478cd5a36f59"  
 timestamp:  "2019-07-20T07:07:58.370733569Z"  
 trace:  "projects/calm-seeker-170606/traces/511012f7f8c08e5d3f7833bdbac6870a"  
}

Xin Zhao

unread,
Jul 22, 2019, 7:46:16 PM7/22/19
to gce-discussion

I checked the http headers with the guide,the http Vary header can only be: Accept, Accept-Encoding, or Origin, but based on your curl output, your http Vary head include: X-Forwarded-Proto,User-Agent, which is not in the list.

You can remove the two parameters in the Vary header, and try again.

For further help, and since it is a technical query, I suggest posting your question on serverfault.com. I hope the above helps.

Peter Ho

unread,
Jul 23, 2019, 4:42:37 AM7/23/19
to gce-discussion
Thank you Fady & Xin Zhao

The following issue updated
- Access-Control-Allow-Origin (Fixed)
- Vary head : X-Forwarded-Proto,User-Agent (Removed and fixed)

It works now with CacheHit = True and seem everything is OK now.

Peter
Reply all
Reply to author
Forward
0 new messages