Skip to main content

Module cache_gcp

Module cache_gcp 

Source
Expand description

Google Cloud CDN purge backend for crate::cache_invalidate::PageCacheInvalidator.

Wires the per-page cache-invalidation hook to Cloud CDN’s urlMaps.invalidateCache Compute Engine API. After a CMS save the public URL is dropped from the Cloud CDN edge so the next request regenerates against the freshly-saved markup instead of waiting for the cache TTL.

§Usage

Behind the cache_gcp feature. Cloud CDN authenticates against the Compute Engine management API with a short-lived OAuth2 bearer token, so the invalidator takes an AccessTokenSource (use StaticToken for scripts/tests; implement the trait against the GCE metadata server for a long-running server):

ⓘ
use std::sync::Arc;
use rustango_cms::cache_gcp::GoogleCloudCdnInvalidator;
use rustango_cms::cache_invalidate::StaticToken;

let inv = GoogleCloudCdnInvalidator::new(
    "my-gcp-project",
    "my-url-map",
    Arc::new(StaticToken(std::env::var("GCP_ACCESS_TOKEN").unwrap())),
)
.with_origin_host("acme.example.com");

let router = rustango_cms::admin::router_with_invalidator(
    tera.clone(),
    Arc::new(inv),
);

The token’s principal needs compute.urlMaps.invalidateCache on the target URL map. Failures are logged through tracing at WARN; the calling admin handler doesn’t propagate the error (cache-invalidation is best-effort by trait contract).

Cloud CDN invalidation is per-path — one API call per path (optionally scoped to a host) — so there’s no bulk endpoint to override; the default PageCacheInvalidator::invalidate_urls loop applies. Subtree purges use Cloud CDN’s /* path glob.

Structs§

GoogleCloudCdnInvalidator
Cloud CDN purge backend. Construct with Self::new; chain .with_* configuration before installing on the admin router.