views:

183

answers:

5

We're experimenting with appending timestamps to some URL's to let things cache but freshen them when they do change. We have code that boils down to this:

DateTime ts = File.GetLastWriteTime(absPath);

where absPath is a MappedPath of a url. So the web server will be checking this file's last write time every time we serve up a link to the file. Kinda gives me the willies - should it?

+6  A: 

You should performance-test it, but off-hand I doubt it's any more expensive than testing a file's existence (e.g. whether it's read-only), and certainly less expensive than actually opening the file.

If (after testing) it you decide that it's a problem, you could also cache your calls to GetLastWriteTime (e.g. don't call it more than once every 5 seconds for any given file).

Also, I've never used it but if caching is a concern I hope you've considered delegating its implementation to some specialist like Squid instead of rolling your own.

ChrisW
A: 

It'll incur additional small disk I/O's when the links are generated. If you create many URL's in a short period of time this could be a bottleneck. Noone can say for sure if this will impact your scenario - you really need to measure and see if this is going to be an issue.

Michael
A: 

Or if you're worried about it, why not cache it for a minute?

Andy Gaskell
+1  A: 

Essentially, there are three answers to your question of "how expensive?".

  1. Too expensive - you've tested it and something has to change for the system to be usable.
  2. Acceptable - you've tested it and it isn't great, but it is fast enough to use
  3. Rather cheap - you've tested it and there is no noticeable impact on performance.

We can't really answer the question for you, so you'll just have to try it out. If you decide that it was too expensive or that it's worth your time to move it from acceptable to rather cheap, change the question to ask how to speed things up.

John Fisher
+2  A: 

I have not tried this, but your question is relevant to a situation that I have been thinking about.

You did not indicate what data is changing? database, xml data etc.

ASP.NET caching does support updating the cache based on a variety of dependencies.

Check out this article in the sections of File-based Dependency, Time-based Dependency, and Key-based Dependency.

"Dependencies allow us to invalidate a particular item within the Cache based on changes to files, changes to other Cache keys, or at a fixed point in time. Let's look at each of these dependencies."

Here is the article:

http://msdn.microsoft.com/en-us/library/ms972379.aspx

Thanks

Joe

Joe Pitz