question

david.a.diaz@gmail.com avatar image
david.a.diaz@gmail.com asked

CDN Access through cloudscript gets an older verion of the file than the client

Hello,

I'm using the following code in cloudscript to access a file:

var cdnUrl = server.GetContentDownloadUrl({
        Key: _url
    }).URL;

var httpResponse = http.request(cdnUrl, "get");

The file referenced by _url was updated 16 hours ago, in the server I was getting the older version of the file so I logged the cdn and non cdn urls within cloudcode:

log.info(("CDN: " + server.GetContentDownloadUrl({
    Key: _url
}).URL);


log.info(("PF: " + server.GetContentDownloadUrl({
    Key: _url,
    ThruCDN: "False"
}).URL);

And accessed them from a web browser, both of them were getting the updated version of the file.

Thanks

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

Actually, it doesn't matter whether you use Cloud Script or the Client call - you just happened to get "lucky" and saw the pattern you did. The fact is that CDN files are cached - that's one of the optimizations that CDNs provide. The edge caches pull content from the origin, which is S3 in this case, if they don't have it locally, then keep it until their TTL expires. This can take up to 24 hours in S3. During that time, you could get either one, depending on which edge server you hit.

The Content system is designed for titles needing to deliver large content to games, so it's not designed to invalidate the content on any update (and besides, that method is slow - taking 20-40 minutes at times, so it doesn't do what I believe you want, which is an immediate update to the edges).

The way to have content always be immediately the latest version is to incorporate the version into the name of the file, and update that whenever you change the content. That would ensure that the Key for the content file is always new, so that the cache is empty whenever it's a new file.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.