3

I'm experienced with ASP.NET but some of my knowledge is a little shaky. I'm creating an application that uses services to get large portions of data. I then want to filter it with LINQ to what I need. This data rarely changes, but I know there's too much of it to fit in Session.

How can I store rarely-changing , large amounts of data in memory? Would this be suitable for Application variables?

4

2 回答 2

1

You can store large amounts of fairly static data:

  • In the HttpContext.Cache
  • In a private static field of a C# class. Wrap the variable with an public get property that can initialize the static field. The static field will need to be initialized when the app first starts, and any time the app domain is recycled by IIS.

HttpContext.Cache

Pro's

  • Configurable cache expiration policy.
  • Designed specifically for the ASP.Net environment

Con's

Static Field

Pro's

  • Complete user control over cache expiration.

Con's

  • Any cache expiration must be explicitly programmed. No built-in expiration support.
于 2012-09-06T00:02:55.540 回答
1

Instead of caching the source data, consider using HTTP caching via ASP.NET Output Cache or memcached to store the rendered output itself. ASP.NET OutputCache can be tuned to work on specific ASP.NET resources and there are many ways to invalidate the cache explicitly if need be. See the following MSDN resources for more information.

ASP.NET Caching Overview

Output Cache Configuration

OutputCache Attribute for ASP.NET MVC

于 2012-09-06T02:00:05.570 回答