package b0

  1. Overview
  2. Docs

Operation cache.

An operation cache combines a file cache and a hash function to memoize build operations.

Note. File hashes performed by this module are cached.

Build operation cache

type t

The type for build operation caches.

val create : ?clock:B0_std.Time.counter -> ?hash_fun:(module B0_std.Hash.T) -> File_cache.t -> t

create ~clock ~hash_fun c is an operation cache with

  • c the file cache used to memoize build operations
  • hash_fun the hash function used to hash files and build operations; defaults to B0_std.Hash.Xxh_64
  • clock the clock used to measure file hashing time and timestamp revived operations defaults to B0_std.Time.counter ().
val set_op_hash : t -> Op.t -> (unit, string) result

set_op_hash t o hashes the operation o and stores the result in o with Op.set_hash. Errors if an input file of the operation can't be hashed.

val revive : t -> Op.t -> (B0_std.Fpath.t list option, string) result

revive c o tries to revive operation o from the file cache using the key Op.hash o. In particular this:

  1. Recreates the files Op.writes o
  2. Sets o's execution information using the metadata hunk of the key. For example for spawn operations this also recovers the exit status code and standard output redirection contents into o.

The semantics of the result is like File_cache.revive; in particular in case of Ok None the key nothing was revived.

Warning. In any case the fields Op.exec_start_time, Op.exec_end_time and Op.exec_status of o get set.

val add : t -> Op.t -> (bool, string) result

add c o adds operation o to the cache. This associates the Op.writes o of o to the key Op.hash o and stores execution information of o in the key's metadata hunk. The semantics of the result is like File_cache.add; in particular in case of Ok false it means some file in the set of writes do not exist and is likely an error.

val hash_fun : t -> (module B0_std.Hash.T)

hash_fun c is the hash function used by the operation cache.

val file_hashes : t -> B0_std.Hash.t B0_std.Fpath.Map.t

file_hashes c is a map of the files that were hashed.

val file_hash_dur : t -> B0_std.Time.span

file_hash_dur c is the time spent hashing files.