@@ -82,10 +82,14 @@ func writeSlice[T any](w io.Writer, tt []T) error {
8282
8383// save saves the users to a file, naming the file based on the filename
8484// and the suffix. The file will be saved in the cache directory.
85- func save [T any ](cacheDir , filename string , suffix string , uu []T ) error {
85+ func save [T any ](cacheDir , filename string , suffix string , uu []T , machineID string ) error {
8686 filename = makeCacheFilename (cacheDir , filename , suffix )
8787
88- f , err := encio .Create (filename )
88+ var opts []encio.Option
89+ if machineID != "" {
90+ opts = append (opts , encio .WithID (machineID ))
91+ }
92+ f , err := encio .Create (filename , opts ... )
8993 if err != nil {
9094 return fmt .Errorf ("failed to create file %s: %w" , filename , err )
9195 }
@@ -101,7 +105,7 @@ func save[T any](cacheDir, filename string, suffix string, uu []T) error {
101105// it as a slice of T.
102106func read [T any ](r io.Reader ) ([]T , error ) {
103107 dec := json .NewDecoder (r )
104- var tt = make ([]T , 0 , 500 ) // 500 T. reasonable?
108+ tt : = make ([]T , 0 , 500 ) // 500 T. reasonable?
105109 for {
106110 var t T
107111 if err := dec .Decode (& t ); err != nil {
@@ -117,14 +121,18 @@ func read[T any](r io.Reader) ([]T, error) {
117121
118122// load loads the data from the file in the cache directory, and returns
119123// the data as a slice of T.
120- func load [T any ](cacheDir , filename string , suffix string , maxAge time.Duration ) ([]T , error ) {
124+ func load [T any ](cacheDir , filename , suffix string , maxAge time.Duration , machineID string ) ([]T , error ) {
125+ var opts []encio.Option
126+ if machineID != "" {
127+ opts = append (opts , encio .WithID (machineID ))
128+ }
121129 filename = makeCacheFilename (cacheDir , filename , suffix )
122130
123131 if err := checkCacheFile (filename , maxAge ); err != nil {
124132 return nil , fmt .Errorf ("%s: %w" , filename , err )
125133 }
126134
127- f , err := encio .Open (filename )
135+ f , err := encio .Open (filename , opts ... )
128136 if err != nil {
129137 return nil , fmt .Errorf ("failed to open %s: %w" , filename , err )
130138 }
0 commit comments