Attempts to read cached content if it's still fresh
(cache_path: &PathBuf)
| 72 | |
| 73 | /// Attempts to read cached content if it's still fresh |
| 74 | fn try_read_cache(cache_path: &PathBuf) -> Result<Option<String>> { |
| 75 | let modified = metadata(cache_path).and_then(|m| m.modified()).unwrap_or(SystemTime::UNIX_EPOCH); |
| 76 | let age = SystemTime::now().duration_since(modified)?; |
| 77 | |
| 78 | if age < Duration::from_secs(CACHE_DURATION_SECS) { Ok(Some(read_to_string(cache_path)?)) } else { Ok(None) } |
| 79 | } |
| 80 | |
| 81 | /// Fetches content from a URL and writes it to the cache |
| 82 | async fn fetch_and_cache(client: &Client, url: &str, cache_path: &PathBuf) -> Result<String> { |