Skip to main content

Module cache_invalidate

Module cache_invalidate 

Source
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 through CachePageLayer::invalidate. Use when the admin handler holds an Arc<BoxedCache> to the same cache the public layer is using.
  • Noop — does nothing. Returned from default() so the trait object can be unconditionally invoked from handler code without Option plumbing.

Structs§

BoxedCacheInvalidator
Built-in invalidator over the same BoxedCache the public CachePageLayer uses. Keys come from the framework’s own CachePageLayer::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 call invalidator.invalidate_url(...).await without if let Some(...) = ... plumbing when the host hasn’t registered a real one.
StaticToken
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 AccessTokenSource against your token endpoint instead so it refreshes.

Traits§

AccessTokenSource
Supplies the OAuth2 bearer token for the cloud-CDN backends that authenticate against a Google / Azure management API.
PageCacheInvalidator
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_paths for the enclosing rustango::sql::atomic block. 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 at Noop.