library_usage/
library_usage.rs1use axum::Router;
2use phantom_frame::{
3 cache::CacheHandle,
4 create_proxy, CacheStrategy, CompressStrategy, CreateProxyConfig, ProxyMode,
5};
6use std::path::PathBuf;
7
8#[tokio::main]
9async fn main() {
10 let proxy_config = CreateProxyConfig::new("http://localhost:8080".to_string())
16 .with_include_paths(vec![
17 "/api/*".to_string(),
18 "/public/*".to_string(),
19 "GET /admin/stats".to_string(), ])
21 .with_exclude_paths(vec![
22 "/api/admin/*".to_string(),
23 "POST *".to_string(), "PUT *".to_string(), "DELETE *".to_string(), ])
27 .caching_strategy(CacheStrategy::None)
28 .compression_strategy(CompressStrategy::Brotli)
29 .with_cache_storage_mode(phantom_frame::CacheStorageMode::Filesystem)
30 .with_cache_directory(PathBuf::from("./.phantom-frame-cache"))
31 .with_websocket_enabled(true); let (proxy_app, handle): (Router, CacheHandle) = create_proxy(proxy_config);
35
36 let handle_clone = handle.clone();
38
39 tokio::spawn(async move {
41 tokio::time::sleep(tokio::time::Duration::from_secs(60)).await;
42
43 handle_clone.invalidate_all();
45 println!("All cache invalidated!");
46
47 tokio::time::sleep(tokio::time::Duration::from_secs(30)).await;
48
49 handle_clone.invalidate("GET:/api/*");
51 println!("Cache invalidated for GET:/api/* pattern!");
52 });
53
54 let _ = ProxyMode::Dynamic; let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
70
71 println!("Proxy server listening on http://0.0.0.0:3000");
72 println!("Caching paths: /api/*, /public/*, GET /admin/stats");
73 println!("Excluding: /api/admin/*, POST *, PUT *, DELETE *");
74 println!("Cache strategy: none (proxy-only mode)");
75 println!("Compression strategy: brotli (applies only to cached responses)");
76 println!("Cache storage mode: filesystem (custom cache directory)");
77 println!("Note: Cache reads and writes are disabled in this example");
78 println!("WebSocket support: enabled");
79
80 axum::serve(listener, proxy_app).await.unwrap();
81}