O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Store Arbitrary Data in the ASP.NET Cache

Problem

You want to use caching, but you can’t cache an entire page because it includes some code that must run or some content that must be generated dynamically.

Solution

Use the built-in Cache object to store most .NET data types.

Discussion

The Cache object allows you to store almost any .NET object using a string key, with the expiration policy you define. ASP.NET maintains the cache automatically, evicting objects when they expire or when memory becomes scarce.

There are two types of expiration policies that you can use when storing data in the cache. Absolute expiration invalidates cached items after a fixed period of time, much like output caching. Absolute expiration is the best approach if you need ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required