如果我没记错的话,ASPX 文件是在运行时编译的,在第一次访问时。将页面编译为 Page 类的内存实例后,针对内存中的对象处理对同一资源(ASPX 页面)的请求。所以本质上,它们是相对于磁盘访问被缓存的。
显然,动态内容是为每个请求生成的,除非使用输出缓存机制进行缓存。
关于内存消耗与磁盘访问时间,我不得不说,从性能的角度来看,将对象存储在内存中而不是每次都从磁盘读取它们是有意义的,如果它们经常使用的话。磁盘访问比 RAM 中的访问慢 2 个数量级。尽管不适当的缓存策略可能会将经常使用的对象从内存中推出,以便为很少使用的对象腾出空间,这可能会因明显的原因而损害性能。话虽如此,缓存对于高性能网站或 Web 应用程序来说非常重要。
作为更新,请考虑以下内容:
- 典型的 DRAM 访问时间在 50 - 200 纳秒之间
- 平均磁盘访问时间在 10 - 20 毫秒范围内
That means that without caching a hit against disk will be ~200 times slower than accessing RAM. Of course, the operating system, the hard-drive and possible other components in between may do some caching of their own so the slow-down may only occur on first hit if you only have a couple such files you're reading from.
Finally, the only way to be certain is to do some benchmarking. Stress-test both implementations and choose the version that works best in your case!