Pregunta

si uso en una página principal

File.ReadAllText 

para cargar un poco de texto desde un archivo de texto, como cadena en un literal.

Cuando voy a cargar el Contenido dependiendo de mi página maestra del código será abrir y leer el archivo de texto todos los tiempos (para cada solicitud de página de contenido) o el archivo de texto se almacenan en caché en la página maestra sólo una vez?

Gracias por su tiempo

¿Fue útil?

Solución

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.

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top