webp-sh / webp_server_go

Go version of WebP Server. A tool that will serve your JPG/PNG/BMP/SVGs as WebP/AVIF format with compression, on-the-fly.
https://docs.webp.sh
GNU General Public License v3.0
1.85k stars 176 forks source link

图片缓存问题 #354

Closed junyangfan closed 3 months ago

junyangfan commented 3 months ago

我有一张更新过的旧照片,图片链接是一样的。如果我删除缓存并再次访问它(即删除 exhaust 文件夹),它仍然与以前相同

config.json

{
  "HOST": "0.0.0.0",
  "PORT": "3333",
  "QUALITY": "80",
  "IMG_PATH": "",
  "EXHAUST_PATH": "/opt/exhaust",
  "IMG_MAP": {
    "/static/images": "https://xxx.com/static/images",
    "/assets/images": "https://xxx.com/assets/images"
  },
  "ALLOWED_TYPES": ["jpg", "png", "jpeg", "bmp", "gif", "svg", "heic", "nef", "webp"],
  "CONVERT_TYPES": ["webp"],
  "STRIP_METADATA": true,
  "ENABLE_AVIF": false,
  "ENABLE_EXTRA_PARAMS": true,
  "EXTRA_PARAMS_CROP_INTERESTING": "InterestingAttention",
  "READ_BUFFER_SIZE": 4096,
  "CONCURRENCY": 512,
  "DISABLE_KEEPALIVE": false,
  "CACHE_TTL": 3600,
  "MAX_CACHE_SIZE": 50
}
n0vad3v commented 3 months ago

对于使用远程地址的图片如果需要手动删除缓存的话需要同时删除 exhaust 目录(优化后图片的缓存)和 remote-raw 目录(原图的缓存),否则仅删除 exhaust 目录的话 WebP Server Go 会继续尝试转换 remote-raw 中的缓存图片并输出。

junyangfan commented 3 months ago

对于使用远程地址的图片如果需要手动删除缓存的话需要同时删除 exhaust 目录(优化后图片的缓存)和 remote-raw 目录(原图的缓存),否则仅删除 exhaust 目录的话 WebP Server Go 会继续尝试转换 remote-raw 中的缓存图片并输出。

请问有没有办法让缓存自动更新?非常感谢

n0vad3v commented 3 months ago

目前可以参考文档中 CACHE_TTL 的配置,在设定时间之后会重新向源站发 HEAD 请求通过 etag 和 content-length 判断文件是否被改变。 https://docs.webp.sh/usage/configuration/

junyangfan commented 3 months ago

目前可以参考文档中 CACHE_TTL 的配置,在设定时间之后会重新向源站发 HEAD 请求通过 etag 和 content-length 判断文件是否被改变。 https://docs.webp.sh/usage/configuration/

是的,我的 config.json 中设置了 CACHE_TTL: 3600,意思是在一小时过后重新向源站发起请求,但是并没有更新相关文件

n0vad3v commented 3 months ago

请仔细阅读哦,这里的单位是分钟,3600 = 60 小时

Cache TTL (minutes) for Remote Backends(Proxy Mode), we use HEAD request to get remote image info, so your backend needs to support HEAD request, after first successfully HEAD request, it will be cached for CACHE_TTL minutes, during that period, we will not send HEAD request again and use local cache for rendering. Setting this value to 0 means cache forever.

(不过确实这里提示的不是很明显,可能容易看错,我们后期会在文档上强调一下这一点

junyangfan commented 3 months ago

请仔细阅读哦,这里的单位是分钟,3600 = 60 小时

Cache TTL (minutes) for Remote Backends(Proxy Mode), we use HEAD request to get remote image info, so your backend needs to support HEAD request, after first successfully HEAD request, it will be cached for CACHE_TTL minutes, during that period, we will not send HEAD request again and use local cache for rendering. Setting this value to 0 means cache forever.

(不过确实这里提示的不是很明显,可能容易看错,我们后期会在文档上强调一下这一点

感谢,我的问题,谢谢解答,后续我测试下

n0vad3v commented 3 months ago

嗯,如果继续出现预期外的情况欢迎随时反馈~