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— purges throughCachePageLayer::invalidate. 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.
Structs§
- Boxed
Cache Invalidator - Built-in invalidator over the same
BoxedCachethe publicCachePageLayeruses. Keys come from the framework’s ownCachePageLayer::invalidate, which purges every cached variant of a path (any query, any vary value), under the tenant it is given. - 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.