balancer
ModuleA purge fanned out over every option a balancer's filters leave.
Contents
use utopia_cdn::cache::balancer::Balancer;Rust
pub struct Balancer<A>Purges through every CdnOption a balancer's filters leave standing.
The balancer holds every configured provider and the filters that narrow them down, so a caller states what to purge and which options qualify, never which API to call. A domain cached by several providers is purged from all of them.
Options are purged one after the other, and one failing does not stop
the rest: the failures are reported together, as Error::Purge, once
every option has been tried. An option that cannot serve the operation
(Error::UnsupportedOperation) is skipped; when every option skips,
the purge fails with Error::UnsupportedOperation. No option left
after the filters is Error::Configuration.
Rust
use std::sync::Arc;
use utopia_balancer::{Balancer as Options, First};
use utopia_cdn::CdnOption;
use utopia_cdn::cache::{Balancer, Cache, Cloudflare, Fastly};
let mut options = Options::new(First);
options
.add_option(CdnOption::new(Arc::new(Fastly::new("token", "domain-").with_service_id("edge")), CdnOption::PROVIDER_FASTLY, true))
.add_option(CdnOption::new(Arc::new(Cloudflare::new("zone", "token")), CdnOption::PROVIDER_CLOUDFLARE, false))
.add_filter(|option: &CdnOption| !option.is_edge());
let cache = Cache::new(Balancer::new(options));
assert_eq!(cache.adapter().options().filtered().len(), 1);
// cache.purge_domain("example.com").await purges through Cloudflare only.