문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top