File.ReadAllText and Master Pages behaviours
if I use in a M开发者_如何学编程aster Page
File.ReadAllText
to load some text from a Text file ,as string in a Literal.
When I will load the Content Page depending on my Master Page the code will open and read the Text file all the times (for every content page request) OR the Text File will be CACHED in the Master Page only once?
Thanks for your time
It will not be cached. Master pages even compiled don't execute the code you've written in them at compilation time.
For example the following thing:
<div><%= File.ReadAllText( someFile ) %></div>
will be compiled to something essentially the same as the following:
builder.Append("<div>").Append( File.ReadAllText( someFile ) ).Append( "</div>" )
which will be executed each time this master page is loaded.
I think your application will read the file multiple times. But the OS will most likely cache the file in RAM, so it should be fast when reading it often.
Alternatively just put it in a cache in your application. But remember "A cache without policy is a memory leak", so you might need a procedure to remove old entries from the cache.
精彩评论