JS cache class

Source: Internet
Author: User

 

 

/*
JS cache class
Call method.
VaR OBJ = new cachehelper ();
OBJ. INIT ();
OBJ. addcache (1, "");
OBJ. addcache (2, "B ");
OBJ. addcache (3, "C ");
OBJ. addcache (4, "D ");
OBJ. addcache (5, "e ");
Alert (obj. getcachebykey (3 ))
*/
Function cachehelper ()
{
This. cache = new array ();
}

Cachehelper. Prototype = {
Init: function (){
This. cache = NULL;
This. cache = new array ();;
},
// Determine whether the cache exists
Isexist: function (ID)
{
For (VAR I = 0; I <this. cache. length; I ++)
{
If (this. cache [I]. ID = ID)
Return true;
}
Return false;
},
// Add Cache
Addcache: function (ID, value)
{
If (! This. isexist (ID ))
{
VaR OBJ = {ID: ID, value: Value };
This. cache. Push (OBJ );
}
},
// Obtain the cache size
Getcachesize: function ()
{
Return this. cache. length;
},
// Obtain the cache value based on the cache key value
Getcachebykey: function (ID)
{
For (VAR I = 0; I <this. cache. length; I ++)
{
If (this. cache [I]. ID = ID)
Return this. cache [I]. value;
}
Return "";
}

}

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.