Sign in

    mizchi/crater-browser-http/cache does not have a README file

    HttpCacheBackend

    pub(open) trait HttpCacheBackend {
    fn lookup(Self, String) -> CacheEntry?
    fn store(Self, CacheEntry) -> Unit
    fn remove(Self, String) -> Unit
    fn clear(Self) -> Unit
    }

    Shared cache backend contract used by cached_fetch.

    CacheDirectives

    pub(all) struct CacheDirectives {
    max_age : Int?
    no_cache : Bool
    no_store : Bool
    must_revalidate : Bool
    public_ : Bool
    private_ : Bool
    immutable : Bool
    } derive(
    Debug
    )

    Parsed Cache-Control header directives

    CacheDirectives::default

    CacheEntry

    pub(all) struct CacheEntry {
    url : String
    status : Int
    headers : Map[String, String]
    body : String
    etag : String?
    last_modified : String?
    directives : CacheDirectives
    stored_at : Double
    } derive(
    Debug
    )

    Cached HTTP response entry

    MemoryCacheBackend

    pub(all) struct MemoryCacheBackend {
    entries : Map[String, CacheEntry]
    max_entries : Int
    }

    In-memory cache backend with LRU-style eviction by oldest stored_at.

    MemoryCacheBackend::clear

    fn MemoryCacheBackend::clear(self : MemoryCacheBackend) -> Unit

    Clear all cache entries.

    MemoryCacheBackend::lookup

    fn MemoryCacheBackend::lookup(self : MemoryCacheBackend, url : String) -> CacheEntry?

    Look up a cache entry by URL. Returns None if not found.

    MemoryCacheBackend::new

    fn MemoryCacheBackend::new(max_entries? : Int) -> MemoryCacheBackend

    MemoryCacheBackend::remove

    fn MemoryCacheBackend::remove(self : MemoryCacheBackend, url : String) -> Unit

    Remove a cache entry by URL.

    MemoryCacheBackend::store

    fn MemoryCacheBackend::store(self : MemoryCacheBackend, entry : CacheEntry) -> Unit

    Store a cache entry. If at capacity and key is new, evict the oldest entry by stored_at.

    cached_fetch

    Fetch with transparent HTTP caching (sync version for testing). Only GET requests are cached. The fetcher parameter allows callers to inject any transport function.

    cached_fetch_async

    Fetch with transparent HTTP caching (async version). Wraps an async fetcher (e.g. @http.fetch) with cache lookup/store. Only GET requests are cached.

    is_cacheable_status

    fn is_cacheable_status(status : Int) -> Bool

    Check if an HTTP status code is cacheable. Only 200, 203, 204, 206, 300, 301, 308 are cacheable by default (RFC 9111 §4.2.2).

    is_fresh

    fn is_fresh(entry : CacheEntry, now : Double) -> Bool

    Check whether a cache entry is still fresh at the given time.

    now_seconds

    fn now_seconds() -> Double

    Get current time in seconds since epoch. Delegates to platform-specific FFI.

    parse_cache_control

    fn parse_cache_control(header : String) -> CacheDirectives

    Parse a Cache-Control header value into CacheDirectives.