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

Function fetch_cached

crates/csskit_spec_generator/src/fetch_cached.rs:63–71  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
63async 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
74fn try_read_cache(cache_path: &PathBuf) -> Result<Option<String>> {

Callers 5

get_web_features_dataFunction · 0.85
get_spec_versionsFunction · 0.85
get_csswg_commit_shaFunction · 0.85
get_specFunction · 0.85
get_css_popularityFunction · 0.85

Calls 3

workspace_target_cacheFunction · 0.85
try_read_cacheFunction · 0.85
fetch_and_cacheFunction · 0.85

Tested by

no test coverage detected