Consider the minimal example: Using php I have a form that you enter text and it produces an image of the text. When I then change the text and update, I don't see the new image because I assume, it is being cached. Is there some way to automatically remove this one image file from the cache when I update it?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Add a query string to the image perhaps containing the julian time + a random number so for example your image URL becomes: //.../myimage.jpg?112233445566-954967254
You can re validate the cache
header("Cache-Control: no-cache, must-revalidate");
This is frequently handled by adding a random string or timestamp to the query.
i.e.
<img src="/images/image.jpg?timestamp=1357571065" />
The typical solution is what ceejazoz gave in this answer: an additional timestamp added as a request parameter. That way the url is different each time, so no cache or proxy will deliver a cached version.
However although that works it is an ugly workaround.
The clean solution is to specify headers when delivering the image. Those headers take care that the image is not cached. That is what headers are there for: defining how resources are meant to be used. The drawback: the out-of-the-box configuration of todays http servers used to deliver static images does not offer to specify such headers. Because in 99,99% of all cases it makes no sense. So you will have to write an own mechanism. Not really difficult, but effort nonetheless. Using the above workaround certainly is easier and less hassle.
And to give a precise answer to your actual question: Cleaning 'the' cache from a single cached object usually is not possible. Though that actually depends on what cache you are talking about. If it is just the browsers cache whilst you are developing (testing), then just make a 'deep reload' (something like CTRL-SHIFT-R or CTRL-F5, depending on your browser). But this clears all cached objects of the current page. There is no easy way to clear a server side cache or even a proxy inbetween.