Fetches content from a URL, using cached content if it's fresh enough If the cache file exists and is less than 24 hours old, returns the cached content. Otherwise, fetches fresh content from the URL and updates the cache.
(client: &Client, url: &str, cache_name: &str)
| 61 | /// If the cache file exists and is less than 24 hours old, returns the cached content. |
| 62 | /// Otherwise, fetches fresh content from the URL and updates the cache. |
| 63 | async fn fetch_cached(client: &Client, url: &str, cache_name: &str) -> Result<String> { |
| 64 | let cache_path = workspace_target_cache()?.join(cache_name); |
| 65 | |
| 66 | if let Some(cached_content) = try_read_cache(&cache_path)? { |
| 67 | return Ok(cached_content); |
| 68 | } |
| 69 | |
| 70 | fetch_and_cache(client, url, &cache_path).await |
| 71 | } |
| 72 | |
| 73 | /// Attempts to read cached content if it's still fresh |
| 74 | fn try_read_cache(cache_path: &PathBuf) -> Result<Option<String>> { |
no test coverage detected