Skip to main content

fetch_with_cache

Function fetch_with_cache 

Source
pub fn fetch_with_cache(
    url: &str,
    filename: &str,
    cache_max_age: f64,
) -> Result<String, BraheError>
Expand description

Fetch a file from a URL with file-based caching.

Checks for a cached copy first. If the cache file exists and is younger than cache_max_age seconds, returns the cached content. Otherwise, downloads from the URL and writes to cache before returning.

§Arguments

  • url - Full URL to fetch
  • filename - Local filename to use in the cache directory
  • cache_max_age - Maximum cache age in seconds

§Returns

  • Result<String, BraheError> - File contents as a string