| 895 | |
| 896 | // Try to look up the cached response |
| 897 | let cached = |
| 898 | cache.lookup_cached_response(&analysis.cache_key).await.unwrap(); |
| 899 | assert!(cached.is_some()); |
| 900 | |
| 901 | let (cached_response, _policy) = cached.unwrap(); |
| 902 | assert_eq!(cached_response.status, StatusCode::OK); |
| 903 | assert_eq!(cached_response.body, b"Hello, world!"); |
| 904 | assert_eq!(cached_response.metadata, Some(b"Metadata".to_vec())); |
| 905 | |
| 906 | // Temporary directory will be automatically cleaned up when dropped |
| 907 | } |
| 908 | |
| 909 | #[tokio::test] |
| 910 | async fn test_http_cache_interface_max_ttl() { |
| 911 | let cache_dir = tempfile::tempdir().unwrap(); |
| 912 | let manager = CACacheManager::new(cache_dir.path().to_path_buf(), true); |
| 913 | let cache = HttpCache { |
| 914 | mode: CacheMode::Default, |
| 915 | manager, |
| 916 | options: HttpCacheOptions { |
| 917 | max_ttl: Some(Duration::ZERO), |
| 918 | ..HttpCacheOptions::default() |
| 919 | }, |
| 920 | }; |
| 921 | |
| 922 | let response = Response::builder() |
| 923 | .status(StatusCode::OK) |
| 924 | .header("cache-control", "max-age=3600") |
| 925 | .body(b"Hello, world!".to_vec()) |
| 926 | .unwrap(); |
| 927 | |
| 928 | let req = Request::builder() |
| 929 | .method("GET") |
| 930 | .uri("https://example.com/test") |
| 931 | .body(()) |
| 932 | .unwrap(); |
| 933 | let (parts, _) = req.into_parts(); |
| 934 | let analysis = cache.analyze_request(&parts, None).unwrap(); |
| 935 | |
| 936 | let processed = cache |
| 937 | .process_response(analysis.clone(), response, None) |
| 938 | .await |