Module Cache.Memory

In-memory HTTP response cache using a Hashtbl. Thread-safe using Eio.Mutex.

type t

The cache type

val create : ?max_entries:int -> unit -> t

Create a new in-memory cache.

  • parameter max_entries

    Maximum number of entries (default 10000)

val store : t -> url:string -> method_:Method.t -> status:int -> headers:Headers.t -> body:string -> request_time:Ptime.t -> response_time:Ptime.t -> ?request_headers:Headers.t -> unit -> bool

Store a response in the cache. Returns true if stored, false if not cacheable.

  • parameter url

    The effective request URI

  • parameter method_

    The HTTP method

  • parameter status

    Response status code

  • parameter headers

    Response headers

  • parameter body

    Response body

  • parameter request_time

    When the request was initiated

  • parameter response_time

    When the response was received

  • parameter request_headers

    Request headers for Vary matching

val lookup : t -> method_:Method.t -> uri:string -> ?request_headers:Headers.t -> now:Ptime.t -> unit -> (entry * lookup_status) option

Look up a cached response.

  • parameter method_

    The HTTP method

  • parameter uri

    The effective request URI

  • parameter request_headers

    Request headers for Vary matching

  • parameter now

    Current time for freshness check

  • returns

    Some (entry, status) if found, None if not in cache

val invalidate : t -> uri:string -> unit

Remove all entries for a URI (used after unsafe methods).

val clear : t -> unit

Clear all entries from the cache.

val size : t -> int

Return the number of entries in the cache.

val stats : t -> int * int * int

Return cache statistics: (hits, misses, stores).