1

I have a program that overwrites a certain set of files required for my website, however the traffic on my website has increased so much that i now get the error File in use. Which results in it being unable to update the file..

This program runs every 5 minutes to update the specified files.

The reason I let this program handle the writing of the file and not the program, is cause I also need to update it to a different webserver (through ftp). this way I also ensure that the file gets updated every 5 minutes, instead of when a user would take a look at page.

My question therefore is; Can i tell IIS7.5 to cache the file after (say 5 seconds to 1 minute) it has been updated? This should ensure that the next time the program runs to update the file it won't encounter any problems.

Raskaroth
  • 639
  • 1
  • 9
  • 25
  • Can you not use the FileSystemWatcher to signal when the file is updated at which time you should be able to create a copy and read from that until the next update is signalled. – Lloyd Jan 04 '12 at 12:28
  • The file in question is on the IIS Server, and it's used by that server too. Hence it is 'in use'. I'm also fairly sure that a FileSystemWatch would have no effect since we are talking about the IIS Server needing to check for update and chache the file. – Raskaroth Jan 04 '12 at 15:10

1 Answers1

1

Simplest solution would be change that program that refreshes the file to store that new information in database, not in filesystem.

But if you can't use database I would take different approach, store file contents to System.Web.Caching.Cache with time when was last modified, and then check if file is changed if not use cached version, and if was changed store new contents and time in same cache variable.

Of course you will have to check if you can read the file, and only then refresh cache contents, and if you can not read the file you can simply get last version from the cache.

Initial reading of file would have to be in application_start to ensure that cache has been initialized, and there you will have to wait until you can read file to store it in the cache for the first time.

Best way to check that you can read from file is to catch exception, because lock can happen after your check, see this post : How to check for file lock?

Community
  • 1
  • 1
Antonio Bakula
  • 20,445
  • 6
  • 75
  • 102
  • hmm okay, well the program is getting part of the information from the database. the reason i'm using that program is to udpate the files on a different webserver as well, though this is being done through ftp without any trouble. I'll just get the data from the database straight for iis server. Thanks! – Raskaroth Jan 04 '12 at 14:21