开发者

Shared data in an ASP.NET application

I have a basic ASP.NET application which is used to request data which is stored on disk. This is loaded from files and sent as the response. I want to be able to store the data loaded from these files in memory to reduce the number of reads from disk.

All of the requests will be asking for the same data, so it makes sense to have a single cache of in-memory data which is accessible to all requests.

What is the best way to create a single accessible object instance which I can use to store and access this cached data? I've looked into HttpApplication, but apparently a new instance of this i开发者_JAVA技巧s created for parallel requests and so it doesn't fit my needs.


First, you could cache the response. Look here: How to cache in ASP.NET by using Visual C# .NET

If you wish you could manually load files into memory and keep their content in static fields. Those will be shared between all clients of the same Application Domain.

Anyway, this will consume the server memory. Make sure you've got enough.


Use the this.Cache.Add / Get

This cache api is simple and works great in moste cases.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜