Question

if I use in a Master 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

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top