开发者

Site caching file, need this to stop

开发者 https://www.devze.com 2023-04-12 06:06 出处:网络
I have a script that generates a new CSV file (in my web directory) every half hour, it replaces the original one and puts a new one in its place with the same file name, the file is linked to on my w

I have a script that generates a new CSV file (in my web directory) every half hour, it replaces the original one and puts a new one in its place with the same file name, the file is linked to on my website.

When I download the file from my website, instead of getting an updated version I get a file that is the same as the first time I downloaded it on this computer.

My first thought was to make sure that the script is still running properly and after testing, I can confirm that it is.

I then cleared the cache and download history in Chrome and tried to download it again, this time it worked as intended.

I am running this off of a rackspace cloud server running ubuntu and apache. I assume there is some setting that I need to reconfigure to fix this problem. Could someone please point me in the right direction.

Thanks 开发者_StackOverflowin advance.


A somewhat dirty solution is to append to the script that let you download the file a random number (or maybe the timestamp) as parameter to prevent the caching.

For example:

www.example.com/download.php?file=my.csv&rand=123456789


The second example on this page shows how to disable caching on many clients and proxies. You should use something like this.

<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>

With this solution, you can cache the page where your link resides. The link will work anyway.

0

精彩评论

暂无评论...
验证码 换一张
取 消