Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How not to cache a downloaded file  RSS feed

 
Tony Evans
Ranch Hand
Posts: 598
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a url link to a file say funds.xls, every day I will replace the file with a new file called funds.xls.

As I understand it there is a chance that the web browser will cache that file, so that the next day say tuesday I click on the link an will see Mondays file which has been cached.

Therefore I am looking at ways to prevent this.

I know in a page you just add



This stops a page from being cached, but I cant see any examples of setting up a link with a parmeter to stop anything being downloaded cached.

Thanks for any help

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Write a servlet that sets the nocache headers and then streams the file. Link to that.
 
Tony Evans
Ranch Hand
Posts: 598
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although your web page does have to cache the file to allow ot to be open, so there fore is there a parameter thats says everytime you click on the link do not use the cached version.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, there is no such "parameter". You'll need to stream the file yourself so that you can add the no cache headers.

An old-fashioned alternative that might work for you is to put a random value as a query parameter on the link.
 
Tony Evans
Ranch Hand
Posts: 598
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear Bibeault

Thanks for the reply

Do you mean write a servlet that builds up the link and then set nocache in the response.

In this case its a little bit more difficult, the link is in content that I set on my page, so I dont build the link. Then the user clicks on that link to download the file.

I was thinking is there any setting in the link itself I can set.

Also are there any good articles that discuss this problem, I could get some ideas from

Thanks again for your reply.

Tony

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, the servlet doesn't set the link, you set the link to point to the servlet.
 
Tony Evans
Ranch Hand
Posts: 598
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks gotcha

Cheers.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!