4

I have a class that is creating an instance of StreamReader to an xml file on the local filesystem. It may be possible that this same file is requested multiple times per-second.

I was wondering whether I need to manually add this file to the System.Web.Cache and read it from there, or whether Windows itself is clever enough to cache the item itself so that it 'knows' when ASP.NET requests this file the second/third etc time that it doesnt have to do a disk seek/read operation and pulls it from its own cache?

This article: http://dotnetperls.com/file-read-benchmarks seems to back this up, but this: article: http://msdn.microsoft.com/en-us/library/18c1wd61%28v=VS.100%29.aspx (although not discussing from a performance perspective, and maybe for other reasons entirely) lists how to add a physical file to the cache.

1 Answer 1

2

I don't think the caching the file would be all that useful, since it resides on the same server as the page, although it probably does get cached automatically by IIS. Instead what you should cache is the output from the StreamReader. Store the xml after you have read it in, and then you will save on the time it takes to read it in and whatever processing you do to get it into a usable format.

Then you can manually add it to the HttpRuntime.Cache and you can even set a file dependency upon the original file, to expire the cached output.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.