MCPcopy Create free account
hub / github.com/csskit/csskit / try_read_cache

Function try_read_cache

crates/csskit_spec_generator/src/fetch_cached.rs:74–79  ·  view source on GitHub ↗

Attempts to read cached content if it's still fresh

(cache_path: &PathBuf)

Source from the content-addressed store, hash-verified

72
73/// Attempts to read cached content if it's still fresh
74fn 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
82async fn fetch_and_cache(client: &Client, url: &str, cache_path: &PathBuf) -> Result<String> {

Callers 1

fetch_cachedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected