Asp.net DataTable cache class

Source: Internet
Author: User

 

Using System;
Using System. Web;
Using System. Data;

Namespace SC
{
/// <Summary>
//**************************************/
// Description: cache class of DateTable.
// Attribute: name: the name of the cache. Write only
// Attribute: Values: read/write cached Values
// Method: CheckCache (): Check whether the cache exists. Return bool
// Method: MakeCacheEmpty (): Clear the cache
// Instance:
// Version 1.0
// Data = 2004-12-13
// Written By: Happy. net
//**************************************/
/// </Summary>
Public class Cache: System. Web. UI. Page
{
Private string name;
Private DataTable strvalue;
Public Cache (string setname)
{
Name = setname;

}

Private void SetCache (string setname, DataTable newvalue)
{
System. Web. HttpContext. Current. Application. Lock ();
System. Web. HttpContext. Current. Application [setname] = newvalue;
System. Web. HttpContext. Current. Application. UnLock ();

}
Public void MakeCacheEmpty () // clear the cache
{
System. Web. HttpContext. Current. Application. Lock ();
System. Web. HttpContext. Current. Application. Remove (name );
System. Web. HttpContext. Current. Application. UnLock ();

}

Public string Name // attribute: Name
{
Set
{
Name = value;
}
}

Public DataTable Values // attribute: cache Value
{
Get
{
Return (DataTable) System. Web. HttpContext. Current. Application [name];
}
Set
{
If (name! = "")
{

Strvalue = value;
SetCache (name, strvalue );
}
Else {}

}

}

Public bool CheckCache () // check the cache
{
Bool boolcheck = false;
If (System. Web. HttpContext. Current. Application [name]! = Null)
{
Boolcheck = true;
}

Return boolcheck;
}

}
}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.