calref / cadence

A strophe.js-powered XMPP web client for chatrooms.
0 stars 0 forks source link

Amazon S3/CloudFront API edge purge #13

Open cburschka opened 9 years ago

cburschka commented 9 years ago

Let's see how that works. Because waiting nearly an hour for the CDN cache to expire after the local content has already updated is bad. In the best case scenario, the local resources haven't changed significantly and your update is just delayed. In the worst case, the new local files are incompatible with the old CDN resources, and you're left with a broken client until it updates. (I think this has happened before.)

cburschka commented 9 years ago

http://www.rackspace.com/blog/cloud-files-cdn-gets-edge-purge/

cburschka commented 9 years ago

It seems to work via a REST HTTP API. Since we're in a shell script, the easiest way to interact with it might be curl:

http://blog.scottlowe.org/2014/02/19/using-curl-to-interact-with-a-restful-api/

cburschka commented 9 years ago

Something like

curl \
  --request DELETE \
  --header "X-Auth-Token: <auth-token>" \
  --header "X-Purge-Email: <user@domain.com>" \
  https://cdn.clouddrive.com/v1/<account-id>/<container>/<object>

(For security, the auth token should probably be read from a file that isn't hosted on github. :P )

cburschka commented 9 years ago

Eg.

CDN_AUTH=$(cat .cdn_auth)
CDN_MAIL=$(cat .cdn_mail)
curl \
  --request DELETE \
  --header "X-Auth-Token: $CDN_AUTH" \
  --header "X-Purge-Email: $CDN_MAIL" \
  https://cdn.clouddrive.com/v1/<account-id>/<container>/<object>
sylae commented 8 years ago

We're now using amazon s3/cloudfront for CDN over rackspace, however the aws cli does have an included feature (albeit experimental): http://docs.aws.amazon.com/cli/latest/reference/cloudfront/create-invalidation.html