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 are the Types of authentications in IIS

595


while developing webservices if i want some users to use my webservice only how can i give security to my webservice?

1406


What is asp.net mvc? : asp.net mvc

548


Can the validation occurs in server-side or client-side? If the validation occurs why should we do?

595


Which methods validate all the controls on a page?

545






What is the difference between CLICK and MOUSE DOWN Event ?

584


What is _dopostback in asp net?

525


what is meant by sitemapnode ?

1499


What is fulltrust?

559


Define what is razor? : asp.net mvc

576


Explain how can you debug your .net application?

531


Explain the difference between webfarm and webgardens in .net?

543


What is the function of new view engine in asp.net? : asp.net mvc

537


Where session id is stored?

533


Explain how cookies work.

596