zoukankan      html  css  js  c++  java
  • js 缓存类

    /*
        js缓存类
        调用方法。
        var obj=new CacheHelper();
        obj.init();
        obj.addCache(1,"a");
        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();;
        },
        //判断缓存是否存在
        isExist:function(id)
        {
            for(var i=0;i<this.cache.length;i++)
            {
                if(this.cache[i].id==id)
                    return true;
            }
            return false;
        },
        //添加缓存
        addCache:function(id,value)
        {
            if(!this.isExist(id))
            {
              var obj={id:id,value:value};
              this.cache.push(obj);
            }
        },
        //取得缓存大小
        getCacheSize:function()
        {
         return this.cache.length; 
        },
        //根据缓存键值取得缓存值
        getCacheByKey:function(id)
        {
         for(var i=0;i<this.cache.length;i++)
            {
                if(this.cache[i].id==id)
                    return this.cache[i].value;
            }
            return "";
        }
       
    }

  • 相关阅读:
    怎样把Maven项目共享为传统Web项目
    伸冤人
    Maven依赖
    Maven常用插件参数
    Maven默认周期与插件
    MySQL Connector_J_5.1.34_2014.10
    MyEclipse2015对Javascript自动提示的终极支持
    Struts Convention Plugin 流程 (2.1.6+)
    Maven,预加载资源文件
    Myeclipse2014 自带的报表功能 与 Eclipse BIRT
  • 原文地址:https://www.cnblogs.com/yg_zhang/p/1601860.html
Copyright © 2011-2022 走看看