Expand description
Targeted page-cache invalidation hook.
The public router (see crate::router()) layers
rustango::cache_page::CachePageLayer in front of CMS page
responses; that layer is TTL-based and emits the response under
a key derived from (method, path, host, vary-on). After an
admin save the public response is stale until the TTL elapses.
This module defines a PageCacheInvalidator trait that the
host app can register on the admin state (crate::admin::AdminState). When
present, every admin handler that mutates a page URL fires the
invalidator on the affected URLs. Hosts that don’t register one
keep the old TTL-only behavior — the trait is purely opt-in.
Two built-in invalidators ship:
BoxedCacheInvalidator— callsCache::deleteon the same key shapeCachePageLayerwrites. Use when the admin handler holds anArc<BoxedCache>to the same cache the public layer is using.Noop— does nothing. Returned fromdefault()so the trait object can be unconditionally invoked from handler code withoutOptionplumbing.
§Key shape
Mirrors the private compute_cache_key in rustango::cache_page:
<prefix>|<method-len>:<method>|<path-len>:<path>|<query-len>:<query>|<host-len>:<host>|...vary_on...For v0 we only target the unadorned GET path: query = “”, no
vary_on headers. Hosts that configure their public layer with
vary_on(...) would need to invalidate every header
combination — declare those upfront via
BoxedCacheInvalidator::with_vary_values.
Structs§
- Boxed
Cache Invalidator - Built-in invalidator that drops keys directly from a
BoxedCache. Use when the host wires the same cache instance into bothCachePageLayerand the admin state. The key shape mirrors whatrustango::cache_pagewrites. - Noop
- No-op invalidator returned from
Arc<dyn PageCacheInvalidator>::default. Lets handler code callinvalidator.invalidate_url(...).awaitwithoutif let Some(...) = ...plumbing when the host hasn’t registered a real one. - Static
Token - Fixed bearer token. Fine for one-shot scripts, short-lived jobs,
and tests; not for a long-running server, where the token will
expire (~1h) — implement
AccessTokenSourceagainst your token endpoint instead so it refreshes.
Traits§
- Access
Token Source - Supplies the OAuth2 bearer token for the cloud-CDN backends that authenticate against a Google / Azure management API.
- Page
Cache Invalidator - Hook called by admin handlers after a page-content mutation.
Implementations should fan out to whatever cache backend the
public router uses (in-memory
CachePageLayer, Cloudflare, Varnish, …) and drop the keys identified by the URL list.
Functions§
- invalidate_
urls_ on_ commit - Register an after-commit purge of
url_pathsfor the enclosingrustango::sql::atomicblock. The purge fires only if the transaction commits — on rollback the queued callback is dropped and nothing is evicted, so a failed save can never knock a still-valid entry out of the public cache. - noop
- Convenience constructor — returns an
Arc<dyn PageCacheInvalidator>pointing atNoop.