google-cloud-platformcloudinfrastructuregoogle-cloud-cdncache-invalidation

GCP Cloud CDN cache invalidation taking too long


I have a simple load balancer setup in GCP with two routing rules,

  1. /api/* which redirect requests to the backend service (managed by cloud Run)
  2. /* which redirects all other requests to a static website hosted in a cloud storage bucket, which contains around 35 resources and the uncompressed build size is around 6MB.

I've only enabled cloud CDN on the bucket and not the backend service in the load balancer and configured cloud CDN with all the recommended settings for caching (also attached below for reference)

enter image description here

Now when I invalidate the cache either using gCloud CLI or using GCP console it takes roughly 10 minutes for the invalidation to complete which shouldn't take this long. following is the gCloud command I'm using to invalidate the cache.

gcloud compute url-maps invalidate-cdn-cache ${URL_MAP_NAME} --path "/*" --project=${GOOGLE_PROJECT_ID}

For reference following is the response of one recent invalidation operation which I manually triggered via the GCP console which shows the operation took more than 10 minutes.

{
  "description": "/*",
  "insertTime": "2023-05-09T04:46:27.108-07:00",
  "startTime": "2023-05-09T04:46:27.109-07:00",
  "endTime": "2023-05-09T04:56:34.458-07:00",
  "kind": "compute#operation",
  "operationType": "invalidateCache",
  "progress": 100,
  "status": "DONE",
   ...
}

I've checked in logs explorer to see if there are any helpful logs which can help in debugging why its taking so long for the invalidation to complete but I don't see any logs related to cache invalidation in the logs explorer, following is the query I'm using to filter logs in the logs explorer

resource.type="http_load_balancer"
resource.labels.url_map_name="${URL_MAP_NAME}"

Are there any concrete steps I can take to reduce the time taken by the invalidation process or anyway I can see some helpful logs to figure out what's happening during these 10 minutes.


Solution

  • Unfortunately, it does not look possible to speed up cache invalidation as it is a global system. If you need consistent/routine cache refreshes, Google recommends using expiration times as cache invalidations are meant for more one-off situations. Also, I would highly recommend that you click the +1 and star buttons to receive notifications regarding the feature request that was raised for this limitation