日期:2014-05-17  浏览次数:20533 次

看了一下缓存感觉挺模糊的 我们只要在页面中定义就ok了吗
页面输出缓存
当用户访问页面时,整个页面将会被服务器保存在内存中,这样就对页面进行了缓存。
当用户再次访问该页,页面不会再次执行数据操作,页面首先会检查服务器中是否存在缓
存,如果缓存存在,则直接从缓存中获取页面信息,如果页面不存在,则创建缓存。
其实我想问的是第二次打开我的首页我的load加载事件难道不执行了,直接去访问缓存?

------解决方案--------------------
从内存中读取数据要比从数据库中获取数据要来得快

我的做法是,只要后台更新了数据再去清缓存,读取是判断后再读取

        public bool Delete(string cCusCode)
        {
            string _cond = " Where cCusCode=@cCusCode ";
            ba_customerinfo _param = new ba_customerinfo();
            _param.cCusCode = cCusCode;
            if (ic.Delete(_cond, _param) > 0)
            {
                clearCache2();
                return true;
            }
            return false;
        }

        public DataTable GetInfoList()
        {
            DataTable dt = cache.RetrieveObject(_index_cache_path2) as DataTable;
            if (dt == null)
            {
                string query = "Select * From BA_Customer";
                dt = dbt.ExecuteTable(query, null);
                dt.PrimaryKey = new DataColumn[] { dt.Columns["cCusCode"] };
                cache.AddObject(_index_cache_path2, dt);
            }
            return dt;
        }
------解决方案--------------------
“其实我想问的是第二次打开我的首页我的load加载事件难道不执行了,直接去访问缓存?”

是这样的,不执行。