Data Caching

How Data Caching achieved in Asp.net 2.0

Questions by InterviewForum

Showing Answers 1 - 3 of 3 Answers

monika_iims

  • May 20th, 2008
 

Using Data Caching
The .NET data caching API is comprised of the two classes in the System.Web.Caching namespace. The first class, Cache, is the class we'll be using to add and remove items from the data cache. The second class, CacheDependency, is used when assigning a cache dependency to an item in the data cache (we'll be discussing this in due time).

To add an item to the cache you can simply do:

' In VB.NET Cache("key") = value  // In C# Cache["key"] = value; 

Note that the C# version uses brackets instead of parenthesis when referencing the items of the cache in the above manner. In the remainder of the examples in this article I will be using VB.NET syntax, but will point out any major differences between the VB.NET and C# syntax.

The above code adds the item value to the data cache with the key key. The key is used to reference the item at some later point. That is, in another ASP.NET Web page we can extract the value inserted above by using:

value = Cache("key")        - or -  value = Cache.Get("key") 

To explicitly remove an item from the data cache you can use the Remove method, specifying the key of the cache item you want removed:

Cache.Remove("key")

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions