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