How to implement caching?

Answer Posted / darshan

Basically cache is used to store frequently accessed data
into the memory, for faster retrieval.

Cache object is dictionary, it stores data in key=>value
pair combination. There are two ways to store the data into
the cache.

1. Cache.Add(key, value, dependance, absolute expiration,
sliding expiration, priority, onRemoveCallback);
2. Cache["key"] = value;

Note: If you are not working in web project, then you might
need to create instance of cache class, like following.

Cache che = new Cache();
che.Add(....);
che["key"] = value;
-----------------------------------------------------------------------
Example:
using System;
using System.Web.Caching;

namespace cacheExample
{
public class Example
{
public static void Main()
{
Cache ch = new Cache();
ch["name"] = "Anonymous";
console.WriteLine("Hello your name is: {0}",
ch["name"].ToString();
}
}
}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is session and application variable in asp net?

651


Explain form level validation and field level validation?

755


What is asp.net caching?

763


Securitywise What are the Enhancements in 2.0?

1670


Explain State management in asp.net

799


What is meant by server side scripting?

705


What is the use of web.config and machine.config files?

841


What are the differences between code behind and code inline?

715


Describe the difference between inline and code behind - which is best in a?

783


How you can access the values from the Repeater control in ASP.NET?

775


What is the use of execute non query in asp.net?

674


What permissions do asp.net applications posses by default?

819


List of words of preprocessor in .net?

695


What is the difference between “Web.config” and “Machine.Config”?

882


How can we use Web API with ASP.NET Web Form?

810