package cache

import (
	

	
)
This cache uses information from the "stat" syscall to try to avoid re- reading files from the file system during subsequent builds if the file hasn't changed. The assumption is reading the file metadata is faster than reading the file contents.

type FSCache struct {
	mutex   sync.Mutex
	entries map[string]*fsEntry
}

type fsEntry struct {
	contents       string
	modKey         fs.ModKey
	isModKeyUsable bool
}

func ( *FSCache) ( fs.FS,  string) (string, error) {
	 := func() *fsEntry {
		.mutex.Lock()
		defer .mutex.Unlock()
		return .entries[]
	}()
If the file's modification key hasn't changed since it was cached, assume the contents of the file are also the same and skip reading the file.
	,  := .ModKey()
	if  != nil && .isModKeyUsable &&  == nil && .modKey ==  {
		return .contents, nil
	}

	,  := .ReadFile()
	if  != nil {
		return "", 
	}

	.mutex.Lock()
	defer .mutex.Unlock()
	.entries[] = &fsEntry{
		contents:       ,
		modKey:         ,
		isModKeyUsable:  == nil,
	}
	return , nil