代码之家  ›  专栏  ›  技术社区  ›  Mahendra Jella

缓存图像正在显示,有人能给我解决方案吗

  •  1
  • Mahendra Jella  · 技术社区  · 6 年前

    之前我有一张尺寸为675*774的图片,我更新了分辨率为250*250的图片,但仍然显示了旧图片。 https://shop.olamsvi.com/pub/media/catalog/category/Picture1_2.png

    当我加载相同的图像时 ?<random_number> 更新后的图像显示尺寸(250*250) https://shop.olamsvi.com/pub/media/catalog/category/Picture1_2.png?22

    我已经删除了我的浏览器缓存,还以匿名方式签入。

    谁能说出问题出在哪里。

    对不起,我英语不好。

    2 回复  |  直到 6 年前
        1
  •  1
  •   Dusan Bajic    6 年前

    显然有 Varnish 在Apache服务器前缓存HTTP反向代理,该服务器为映像的缓存副本提供服务(因为它被配置为这样做)。

    您可以从HTTP响应头中观察到:

     $  curl -v -s https://shop.olamsvi.com/pub/media/catalog/category/Picture1_2.png -o file.png
    *   Trying 52.163.125.20...
    * TCP_NODELAY set
    * Connected to shop.olamsvi.com (52.163.125.20) port 443 (#0)
    ...
    > GET /pub/media/catalog/category/Picture1_2.png HTTP/1.1
    > Host: shop.olamsvi.com
    > User-Agent: curl/7.54.0
    > Accept: */*
    >
    < HTTP/1.1 200 OK
    < Date: Mon, 04 Jun 2018 11:52:41 GMT
    < Server: Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.1e-fips PHP/7.0.21
    < Content-Length: 410771
    < Accept-Ranges: bytes
    < Access-Control-Allow-Origin: *
    < X-Frame-Options: SAMEORIGIN
    < X-Varnish: 41773
    < Age: 0
    < Via: 1.1 varnish (Varnish/5.2)
    < X-Original-Content-Length: 561788
    < Etag: W/"PSA-aj-giNrXrkKdK"
    < Expires: Fri, 22 Mar 2019 05:53:09 GMT
    < Cache-Control: max-age=25120827, public
    < X-Content-Type-Options: nosniff
    < Content-Type: image/png
    <
    { [16384 bytes data]
    * Connection #0 to host shop.olamsvi.com left intact
    

    不是那个 Via: 1.1 varnish (Varnish/5.2) Expires: Fri, 22 Mar 2019 05:53:09 GMT 线 缓存静态资源通常是非常有益的,但您也应该考虑这种方式 how to invalidate it (什么时候做)

        2
  •  0
  •   Aram Grigoryan    6 年前

    拜托,你能看到这个答案吗?

    <IfModule mod_expires.c> 
      ExpiresActive On
      ExpiresDefault "access plus 1 seconds"
      ExpiresByType text/html "access plus 1 seconds"
      ExpiresByType image/x-icon "access plus 2592000 seconds"
      ExpiresByType image/gif "access plus 2592000 seconds"
      ExpiresByType image/jpeg "access plus 2592000 seconds"
      ExpiresByType image/png "access plus 2592000 seconds"
      ExpiresByType text/css "access plus 604800 seconds"
      ExpiresByType text/javascript "access plus 86400 seconds"
      ExpiresByType application/x-javascript "access plus 86400 seconds"
    </IfModule>
    

    https://stackoverflow.com/a/13029007/4553685

    也许对你有帮助