Fields
cache: *Cache,
hash: HashHelper,
Current state for incremental hashing.
manifest_dirty: bool,
want_shared_lock: bool = true,
Set this flag to true before calling hit() in order to indicate that upon a cache hit, the code using the cache will not modify the files within the cache directory. This allows multiple processes to utilize the same cache directory at the same time.
have_exclusive_lock: bool = false,
want_refresh_timestamp: bool = true,
files: field_call = .{ },
hex_digest: [hex_digest_len]u8,
failed_file_index: ?usize = null,
Populated when hit() returns an error because of one of the files listed in the manifest.
recent_problematic_timestamp: i128 = 0,
Keeps track of the last time we performed a file system write to observe what time the file system thinks it is, according to its own granularity.
Functions
fn addDepFilePost(self: *Manifest, dir: fs.Dir, dep_file_basename: []const u8) !void
No documentation provided.
fn addFile(self: *Manifest, file_path: []const u8, max_file_size: ?usize) !usize
Add a file as a dependency of process being cached. When
hit
is called, the f…Add a file as a dependency of process being cached. When
hit
is called, the file’s contents will be checked to ensure that it matches the contents from previous times.Max file size will be used to determine the amount of space the file contents are allowed to take up in memory. If max_file_size is null, then the contents will not be loaded into memory.
Returns the index of the entry in the
files
array list. You can use it to access the contents of the file after callinghit()
like so:var file_contents = cache_hash.files.items[file_index].contents.?;
fn addFilePost(self: *Manifest, file_path: []const u8) !void
Add a file as a dependency of process being cached, after the initial hash has b…
Add a file as a dependency of process being cached, after the initial hash has been calculated. This is useful for processes that don’t know the all the files that are depended on ahead of time. For example, a source file that can import other files will need to be recompiled if the imported file is changed.
fn addFilePostContents(self: *Manifest, resolved_path: []u8, bytes: []const u8, stat: File.Stat) error{OutOfMemory}!void
Like
addFilePost
but when the file contents have already been loaded from disk…Like
addFilePost
but when the file contents have already been loaded from disk. On success, cache takes ownership ofresolved_path
.fn addFilePostFetch(self: *Manifest, file_path: []const u8, max_file_size: usize) ![]const u8
Add a file as a dependency of process being cached, after the initial hash has b…
Add a file as a dependency of process being cached, after the initial hash has been calculated. This is useful for processes that don’t know all the files that are depended on ahead of time. For example, a source file that can import other files will need to be recompiled if the imported file is changed.
fn addListOfFiles(self: *Manifest, list_of_files: []const []const u8) !void
No documentation provided.
fn addOptionalFile(self: *Manifest, optional_file_path: ?[]const u8) !void
No documentation provided.
fn deinit(self: *Manifest) void
Releases the manifest file and frees any memory the Manifest was using. `Manife…
Releases the manifest file and frees any memory the Manifest was using.
Manifest.hit
must be called first. Don’t forget to callwriteManifest
before this!fn hit(self: *Manifest) !bool
Check the cache to see if the input exists in it. If it exists, returns
true
. …Check the cache to see if the input exists in it. If it exists, returns
true
. A hex encoding of its hash is available by callingfinal
.This function will also acquire an exclusive lock to the manifest file. This means that a process holding a Manifest will block any other process attempting to acquire the lock. If
want_shared_lock
istrue
, a cache hit guarantees the manifest file to be locked in shared mode, and a cache miss guarantees the manifest file to be locked in exclusive mode.The lock on the manifest file is released when
deinit
is called. As another option, one may calltoOwnedLock
to obtain a smaller object which can represent the lock.deinit
is safe to call whether or nottoOwnedLock
has been called.fn toOwnedLock(self: *Manifest) Lock
Obtain only the data needed to maintain a lock on the manifest file. The `Manif…
Obtain only the data needed to maintain a lock on the manifest file. The
Manifest
remains safe to deinit. Don’t forget to callwriteManifest
before this!fn unhit(self: *Manifest, bin_digest: BinDigest, input_file_count: usize) void
No documentation provided.
fn writeManifest(self: *Manifest) !void
If
want_shared_lock
is true, this function automatically downgrades the lock …If
want_shared_lock
is true, this function automatically downgrades the lock from exclusive to shared.