简体   繁体   English

File.ReadAllText使用CACHE

[英]File.ReadAllText use of CACHE

I would like to know behavior for method File.ReadAllText Here an example of my code: 我想知道方法File.ReadAllText的行为,这里是我的代码示例:

uxJavaScriptTinyMCEDisplayer.Text = File.ReadAllText(Server.MapPath("TinyMCEJavaScriptAdmin.txt"));

File.ReadAllText have some CACHE behavior? File.ReadAllText有一些CACHE行为吗? So taht the first time the file is read, will be kept in memory and not re-read again? 那么,第一次读取文件时,该文件将保留在内存中,而不会再次读取吗?

thanks 谢谢

There is no direct caching in .Net, however, you get caching behaviour indirectly via the OS. .Net中没有直接缓存,但是,您可以通过OS间接获得缓存行为。

Windows is very much optimized to cache file contents in memory and has a layer that facilitates in-memory caching of file system contents. Windows已经过优化,可以将文件内容缓存在内存中,并且具有一层有助于文件系统内容在内存中进行缓存的层。 But as Frédéric points out in his comment, you should not rely on this behaviour as memory pressure, cache ageing, etc, may mean that cached content is dropped. 但是正如Frédéric在他的评论中指出的那样,您不应该依赖此行为,因为内存压力,缓存老化等可能意味着缓存内容被丢弃。

The OS does a good job of caching if there is plenty of memory. 如果有足够的内存,则操作系统可以很好地进行缓存。

Update 更新资料

This is an old article (Win2K) but gives some idea as to OS disk caching. 这是一篇老文章(Win2K),但对OS磁盘缓存给出了一些想法。

http://technet.microsoft.com/en-us/library/bb742613.aspx http://technet.microsoft.com/zh-CN/library/bb742613.aspx

No cache. 没有缓存。 It will read the current contents of the file at the given path. 它将在给定路径下读取文件的当前内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM