feat: use real image path to calculate cache key
This commit is contained in:
@@ -91,7 +91,7 @@ func handleImagePreview(
|
||||
return errToStatus(err), err
|
||||
}
|
||||
|
||||
cacheKey := previewCacheKey(file.Path, file.ModTime.Unix(), previewSize)
|
||||
cacheKey := previewCacheKey(file, previewSize)
|
||||
resizedImage, ok, err := fileCache.Load(r.Context(), cacheKey)
|
||||
if err != nil {
|
||||
return errToStatus(err), err
|
||||
@@ -142,7 +142,7 @@ func createPreview(imgSvc ImgService, fileCache FileCache,
|
||||
}
|
||||
|
||||
go func() {
|
||||
cacheKey := previewCacheKey(file.Path, file.ModTime.Unix(), previewSize)
|
||||
cacheKey := previewCacheKey(file, previewSize)
|
||||
if err := fileCache.Store(context.Background(), cacheKey, buf.Bytes()); err != nil {
|
||||
fmt.Printf("failed to cache resized image: %v", err)
|
||||
}
|
||||
@@ -151,6 +151,6 @@ func createPreview(imgSvc ImgService, fileCache FileCache,
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func previewCacheKey(fPath string, fTime int64, previewSize PreviewSize) string {
|
||||
return fmt.Sprintf("%x%x%x", fPath, fTime, previewSize)
|
||||
func previewCacheKey(f *files.FileInfo, previewSize PreviewSize) string {
|
||||
return fmt.Sprintf("%x%x%x", f.RealPath(), f.ModTime.Unix(), previewSize)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user