dongli8466 2013-08-14 09:13
浏览 33

清除特定映像的Apache缓存

I implemented a system to edit images displayed on a website.

When an image is edited, I want to display its last version on all pages of the site (where it's called), at least for the user who edited the image.

Now I'm searching a better way to clear the cache for a specific image than adding the timestamp to the end :

<img src="myimage.jpg?01215654" alt="" />

Why ?

It supposes to always add the timestamp at the end of the image path, with a session system for example.

But when the session expires (for example, user leaves the site, and go back few hours after), the real path of the image is displayed :

<img src="myimage.jpg" alt="" />

And the navigator randomly displays the old image, or the last version... Because Apache cached :

  • myimage.jpg as the old image
  • myimage.jpg?01215654 as the new version because no one hit it before (was loaded as a new media)

Limitations

  • I can't change the path of an edited image, for example "myimage.jpg" to "myimage-v2.jpg", which could solve the problem...
  • Images are not served from a controller (not served from a PHP script), they are direclty loaded from their path on the server.
  • I don't want to use a session system that add timestamp or version string at the end of an image path with JS.

What I want

I want to say that the cache of "myimage.jpg" has expired, and so to display the last version, and then cache it normally, until the next edition. So I would like to load the image with "200 status", and not "304 modified" after an edit.

Note : when an image is edited, I reload it with JS (JQuery) in a hidden div, if you now a way to change cache header ?

So what I want is to clear the cache header of a specific image that is edited, taking into account the limitations of my project, so if possible by using cache directives without serving the image from a controller, is it possible ?

  • 写回答

1条回答 默认 最新

  • dpc57092 2014-03-15 21:55
    关注

    This whole question is very confused.

    Apache cache? ...No, the cache is in your browser, not in Apache.

    Sessions adding timestamps to image URLs? ...No, the querystring with the timestamp must be added to the HTML using server-side script (such as PHP, for example). It has nothing whatsoever to do with browser sessions. (And actually it's generally much better to use the file last-modified time rather than the current timestamp, BTW).

    There are a number of ways to achieve the effect you want, each with its own benefits and drawbacks depending on your situation. You may want to read my answer here.

    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧