// Package cache provides disk cache for Actions
package cache import ( ) func ( string, export.Export) ( error) { var []byte if , = json.Marshal(); == nil { = Write(, ) } return } func ( string, []byte) ( error) { return os.WriteFile(, , 0600) } func ( string, time.Duration) (*export.Export, error) { // TODO reference , := Load(, ) if != nil { return nil, } var export.Export if := json.Unmarshal(, &); != nil { return nil, } return &, nil } func ( string, time.Duration) ( []byte, error) { var os.FileInfo if , = os.Stat(); os.IsNotExist() || ( >= 0 && .ModTime().Add().Before(time.Now())) { return nil, errors.New("not exists or timeout exceeded") } return os.ReadFile() } // CacheDir creates a cache folder for current user and returns the path. func ( string) ( string, error) { var string , = xdg.UserCacheDir() if != nil { return } if , := env.Sandbox(); == nil { = .CacheDir() } = fmt.Sprintf("%v/carapace/%v/%v", , uid.Executable(), ) = os.MkdirAll(, 0700) return } // File returns the cache filename for given values // TODO cleanup func ( string, int, ...key.Key) ( string, error) { := uidKeys(, strconv.Itoa()) := make([]string, 0) for , := range { , := () if != nil { return "", } = append(, ) } if , := CacheDir(); == nil { = + "/" + uidKeys(...) } return } func uidKeys( ...string) string { return fmt.Sprintf("%x", sha1.Sum([]byte(strings.Join(, "\001")))) }