MCPcopy Index your code
hub / github.com/perkeep/perkeep / scaledCached

Method scaledCached

pkg/server/image.go:180–208  ·  view source on GitHub ↗

ScaledCached reads the scaled version of the image in file, if it is in cache and writes it to buf. On successful read and population of buf, the returned format is non-empty. Almost all errors are not interesting. Real errors will be logged.

(ctx context.Context, buf *bytes.Buffer, file blob.Ref)

Source from the content-addressed store, hash-verified

178// On successful read and population of buf, the returned format is non-empty.
179// Almost all errors are not interesting. Real errors will be logged.
180func (ih *ImageHandler) scaledCached(ctx context.Context, buf *bytes.Buffer, file blob.Ref) (format string) {
181 key := cacheKey(file.String(), ih.MaxWidth, ih.MaxHeight)
182 br, err := ih.ThumbMeta.Get(key)
183 if err == errCacheMiss {
184 return
185 }
186 if err != nil {
187 log.Printf("Warning: thumbnail cachekey(%q)->meta lookup error: %v", key, err)
188 return
189 }
190 fr, err := ih.cached(ctx, br)
191 if err != nil {
192 if imageDebug {
193 log.Printf("Could not get cached image %v: %v\n", br, err)
194 }
195 return
196 }
197 defer fr.Close()
198 _, err = io.Copy(buf, fr)
199 if err != nil {
200 return
201 }
202 mime := magic.MIMEType(buf.Bytes())
203 if format = strings.TrimPrefix(mime, "image/"); format == mime {
204 log.Printf("Warning: unescaped MIME type %q of %v file for thumbnail %q", mime, br, key)
205 return
206 }
207 return format
208}
209
210// Gate the number of concurrent image resizes to limit RAM & CPU use.
211

Callers 1

ServeHTTPMethod · 0.95

Calls 7

cachedMethod · 0.95
MIMETypeFunction · 0.92
cacheKeyFunction · 0.85
PrintfMethod · 0.80
GetMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected