Barguast
Barguast

Reputation: 295

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 is created for parallel requests and so it doesn't fit my needs.

Upvotes: 2

Views: 613

Answers (2)

user151323
user151323

Reputation:

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.

Upvotes: 2

Peter
Peter

Reputation: 38455

Use the this.Cache.Add / Get

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

Upvotes: 0

Related Questions