code: func (ih *ImageHandler) scaledCached(ctx context.Context, buf *bytes.Buffer, file blob.Ref) (format string) {
  	key := cacheKey(file.String(), ih.MaxWidth, ih.MaxHeight)
  	br, err := ih.ThumbMeta.Get(key)
  	if err == errCacheMiss {
  		return
  	}
  	if err != nil {
  		log.Printf("Warning: thumbnail cachekey(%q)->meta lookup error: %v", key, err)
  		return
  	}
  	fr, err := ih.cached(ctx, br)
  	if err != nil {
  		if imageDebug {
  			log.Printf("Could not get cached image %v: %v\n", br, err)
  		}
  		return
  	}
  	defer fr.Close()
  	_, err = io.Copy(buf, fr)
  	if err != nil {
  		return
  	}
  	mime := magic.MIMEType(buf.Bytes())
  	if format = strings.TrimPrefix(mime, "image/"); format == mime {
  		log.Printf("Warning: unescaped MIME type %q of %v file for thumbnail %q", mime, br, key)
  		return
  	}
  	return format
  }
docs: // 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.