using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Datacache : System.Web.UI.Page
{
private DataTable dtEmployee;
protected void Page_Load(object sender, EventArgs e)
{
TimeSpan ts = new TimeSpan(0, 0, 10);
//If cache has null, it will create two cache
// and it will bind into the gridview
if (Cache["Employee"] == null)
{
dtEmployee = new DataTable("Employee");
dtEmployee.Columns.Add("EmpID", typeof(int));
dtEmployee.Columns.Add("EmpName", typeof(string));
DataRow rs = dtEmployee.NewRow();
rs[0] = 10;
rs[1] = "Annathurai";
dtEmployee.Rows.Add(rs);
//To assign datatable to cache memory.
Cache["Employee"] = dtEmployee; Response.Write("Its processing with Database hit");
}
else
{
//If cache has value, It retrive from cache memory and bind into the gridview
Response.Write("Its processing from cache");
}
// Here we are converting cache into datatable
GridView1.DataSource = (DataTable)Cache["Employee"];
GridView1.DataBind();
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.