首页 新闻 会员 周边

没专家分了,但真诚求教关于asp.net缓存的问题

0
[已关闭问题]

这几天学习到了asp.net缓存.有诸多问题,demo代码如下:
CacheItemRemovedCallback callback = null;
CacheDependency depend = null;
public void removecallback(string key, Object value, CacheItemRemovedReason reason)
        {
            depend = new CacheDependency(Server.MapPath("/aa.xml"));
            //代码(此处存在疑问)
           Cache.Insert("knumber", new SiteConfig().GetConfig().RemarkNumber, depnd, DateTime.Now.AddSeconds(5), TimeSpan.Zero, CacheItemPriority.Default, removecallback);
        }
        /// <summary>
        /// 更新缓存建立依赖并自动回调
        /// </summary>
        public void updateCahcecallback()
        {
            depend = new CacheDependency(Server.MapPath("/aa.xml"));
            callback = new CacheItemRemovedCallback(removecallback);
            Cache.Insert("knumber", new SiteConfig().GetConfig().RemarkNumber, depnd, DateTime.Now.AddSeconds(5), TimeSpan.Zero, CacheItemPriority.Default, callback);  //new SiteConfig().GetConfig().RemarkNumber为获取remarknumber值
        }
---------------
protected void Button4_Click(object sender, EventArgs e)
        {
            string sqlText = "update site_config set remarkNumber='" + TextBox1.Text + "' where id=1";
            Ecms.DALProfile.OledbDbHelper.ExecuteNonQuery(sqlText);
            FileObject.WriteFile(Server.MapPath("/aa.xml"), TextBox1.Text, false);   //此处为将textbox1.text的内容写入aa.xml
            updateCahcecallback();

问题:
 1.第二个函数中的cache.insert()的写法可不可以这样理解:绝对过期时间5秒种,缓存依赖于aa.xml文件,5秒钟后缓存将自动更新,或在这5秒钟内更新aa.xml文件缓存也将更新.
 2.removecallback回调函数的功能应该为重新更新缓存.并且功能与updateCahcecallback功能一样.但不知道如何写!!!加粗部分代码是我自己写的好像会导致数据库无法关闭.请指教

3.无论用什么缓存方式.是不是每次在读取缓存时都必须要判断一下缓存是否存在?

沉默杨的主页 沉默杨 | 初学一级 | 园豆:6
提问于:2009-05-27 12:48
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册