Maintenance and cache
Deployed and supported. The fields and commands described here are stable within version v1alpha1.
A static site is served through a cache: visitors receive a copy kept for up to an hour. This guide shows how to put a site in maintenance without losing its content, when and how to clear the cache, and how to delete a site.
Prerequisites
- A published site: Publish a static site.
- The rights
cdn:write(maintenance),cdn:purge(cache),cdn:delete(deletion): included in the managed policiesreadwriteandadmin.
1. Put a site in maintenance
sng cdn disable docs
site docs en maintenance (effectif dans quelques minutes)
The site then responds 503 Service Unavailable to all requests, with a
maintenance page, the header Retry-After: 300 and Cache-Control: no-store. The content, the
domain and the certificate are kept. You can keep publishing
(sng cdn upload) during maintenance.
Allow a few minutes before the change is visible. So that no visitor keeps the old version in cache in the meantime, the platform clears the site's cache immediately, then again several times in the following minutes.
As a manifest: spec.maintenanceMode: true, then sng apply.
2. Reactivate the site
sng cdn enable docs
site docs réactivé (effectif dans quelques minutes)
sng cdn list displays disabled for a site in maintenance, enabled otherwise. Both
commands have no effect if the site is already in the requested state.
3. Understand the cache duration
| Response | Duration in cache |
|---|---|
| file found | Cache-Control: public, max-age=3600 (1 hour), plus 5 minutes of grace |
404 | 30 seconds |
| maintenance page, other errors | never |
sng cdn upload clears the site's cache at the end of each upload: a new version is
visible right away, without waiting for expiration.
4. Clear the cache by hand
Useful after a change outside sng cdn upload (site served from your own bucket),
or to avoid waiting the 30 seconds of a 404 cached before the file arrived:
sng cdn clear-cache docs
cache du site docs vidé
The cache is cleared for the site's whole domain. Alias:
clear_cache.
5. Delete a site
sng cdn delete docs
⚠ Suppression définitive du site "docs" et de son contenu (tenant "acme").
Tapez « oui » pour confirmer : oui
site docs supprimé (42 fichier(s) retiré(s))
The site, all its content (default storage) and its cache are deleted; nothing is
recoverable. A site served from your own bucket does not touch it: your files stay
in your bucket. From a script: --yes. sng kind delete CDNSite docs has the same effect.
Verification
curl -sI https://docs.acme.dev.stackngo.app/ | head -3
HTTP/2 503
cache-control: no-store
content-type: text/html; charset=utf-8
After sng cdn enable, the same command returns HTTP/2 200.
Going further
- Cache duration per file: cannot be set with
sng cdn uploadin this version (the uploaded files have noCache-Controlheader of their own). A site served from your bucket uses theCache-Controlof each object if it has one. - Cache cleared without the right: if your identity does not have
cdn:purge,sng cdn uploadpublishes anyway but warnsattention : cache non vidé, relancez sng cdn clear-cache docs. - What the visitor sees during a storage outage: a StackNGO home page
(
200, never cached), until storage comes back. - API:
disableandenablemap toPOST /v1/cdn/{name}/disable|enable(cdn:write),clear-cachetoPOST /v1/cdn/{name}/cache/clear(cdn:purge, response204),deletetoDELETE /v1/cdn/{name}(cdn:delete).
See also
- Publish a static site
- Reference:
sng cdn,CDNSite