pub struct RefreshTrigger { /* private fields */ }Expand description
A trigger that can be cloned and triggered multiple times Similar to oneshot but reusable
Implementations§
Source§impl RefreshTrigger
impl RefreshTrigger
pub fn new() -> Self
Sourcepub fn trigger(&self)
pub fn trigger(&self)
Trigger a cache refresh
Examples found in repository?
examples/library_usage.rs (line 33)
5async fn main() {
6 // Initialize tracing (optional but recommended)
7 // tracing_subscriber::fmt::init();
8
9 // Create proxy configuration
10 // You can specify method prefixes to filter by HTTP method
11 let proxy_config = CreateProxyConfig::new("http://localhost:8080".to_string())
12 .with_include_paths(vec![
13 "/api/*".to_string(),
14 "/public/*".to_string(),
15 "GET /admin/stats".to_string(), // Only cache GET requests to this endpoint
16 ])
17 .with_exclude_paths(vec![
18 "/api/admin/*".to_string(),
19 "POST *".to_string(), // Don't cache any POST requests
20 "PUT *".to_string(), // Don't cache any PUT requests
21 "DELETE *".to_string(), // Don't cache any DELETE requests
22 ]);
23
24 // Create proxy - proxy_url is the backend server to proxy requests to
25 let (proxy_app, refresh_trigger): (Router, RefreshTrigger) = create_proxy(proxy_config);
26
27 // You can clone and use the refresh_trigger in your code
28 let trigger_clone = refresh_trigger.clone();
29
30 // Example: Trigger cache refresh from another part of your application
31 tokio::spawn(async move {
32 tokio::time::sleep(tokio::time::Duration::from_secs(60)).await;
33 trigger_clone.trigger();
34 println!("Cache refreshed!");
35 });
36
37 // Start the proxy server
38 let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
39
40 println!("Proxy server listening on http://0.0.0.0:3000");
41 println!("Caching paths: /api/*, /public/*, GET /admin/stats");
42 println!("Excluding: /api/admin/*, POST *, PUT *, DELETE *");
43 println!("Note: Only GET requests will be cached (POST/PUT/DELETE are excluded)");
44
45 axum::serve(listener, proxy_app).await.unwrap();
46}Trait Implementations§
Source§impl Clone for RefreshTrigger
impl Clone for RefreshTrigger
Source§fn clone(&self) -> RefreshTrigger
fn clone(&self) -> RefreshTrigger
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for RefreshTrigger
impl !RefUnwindSafe for RefreshTrigger
impl Send for RefreshTrigger
impl Sync for RefreshTrigger
impl Unpin for RefreshTrigger
impl !UnwindSafe for RefreshTrigger
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more