(r io.Reader, contentMetadata ContentMetadata, key *Key)
| 165 | } |
| 166 | |
| 167 | func (f *fileSystemCache) Put(r io.Reader, contentMetadata ContentMetadata, key *Key) (time.Duration, error) { |
| 168 | fp := key.filePath(f.dir) |
| 169 | file, err := os.Create(fp) |
| 170 | |
| 171 | if err != nil { |
| 172 | return 0, fmt.Errorf("cache %q: cannot create file: %s : %w", f.Name(), key, err) |
| 173 | } |
| 174 | |
| 175 | if err := writeHeader(file, contentMetadata.Type); err != nil { |
| 176 | fn := file.Name() |
| 177 | return 0, fmt.Errorf("cannot write Content-Type to %q: %w", fn, err) |
| 178 | } |
| 179 | |
| 180 | if err := writeHeader(file, contentMetadata.Encoding); err != nil { |
| 181 | fn := file.Name() |
| 182 | return 0, fmt.Errorf("cannot write Content-Encoding to %q: %w", fn, err) |
| 183 | } |
| 184 | |
| 185 | if err := writeHeader(file, fmt.Sprintf("%d", contentMetadata.Length)); err != nil { |
| 186 | fn := file.Name() |
| 187 | return 0, fmt.Errorf("cannot write Content-Encoding to %q: %w", fn, err) |
| 188 | } |
| 189 | |
| 190 | cnt, err := io.Copy(file, r) |
| 191 | if err != nil { |
| 192 | return 0, fmt.Errorf("cache %q: cannot write results to file: %s : %w", f.Name(), key, err) |
| 193 | } |
| 194 | |
| 195 | atomic.AddUint64(&f.stats.Size, uint64(cnt)) |
| 196 | atomic.AddUint64(&f.stats.Items, 1) |
| 197 | return f.expire, nil |
| 198 | } |
| 199 | |
| 200 | func (f *fileSystemCache) cleaner() { |
| 201 | d := f.expire / 2 |
nothing calls this directly
no test coverage detected