zoukankan      html  css  js  c++  java
  • .net 缓存之文件缓存依赖

    CaCheHelp 类中代码如下:

    #region 根据键从缓存中读取保持的数据
            /// <summary>
            /// 根据键从缓存中读取保持的数据
            /// </summary>
            /// <param name="CaCheKey">索引键值</param>
            /// <returns></returns>
            public static object GetCaChe(string CaCheKey)
            {
                System.Web.Caching.Cache ca = HttpRuntime.Cache;
                return ca[CaCheKey];
            }
            #endregion
    
            #region 设置当前应用程序中指定的缓存项  重载  设置依赖项
            /// <summary>
            /// 设置当前应用程序中指定的缓存项  重载  设置依赖项
            /// </summary>
            /// <param name="CaCheKey">索引键值</param>
            /// <param name="objValue">缓存对象</param>
            /// <param name="dep">依赖对象</param>
            public static void SetCaChe(string CaCheKey, object objValue, System.Web.Caching.CacheDependency dep)
            {
                System.Web.Caching.Cache ca = HttpRuntime.Cache;
                ca.Insert(CaCheKey, objValue, dep,System.Web.Caching.Cache.NoAbsoluteExpiration,System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Default,null);
            } 
            #endregion

    页面调用:

    string CaCheKey = "cachekey";
                object objModel = CaCheHelp.GetCaChe(CaCheKey);
                
                if (objModel == null)
                {
                    objModel = DateTime.Now;
                    if (objModel != null)
                    {
                        System.Web.Caching.CacheDependency dep = new System.Web.Caching.CacheDependency("D:\CacheTest.txt");//依赖D盘下CacheTest.txt内容改变时更新缓存
                        CaCheHelp.SetCaChe(CaCheKey, objModel, dep);
                    }
    
                }
                
                lable_time.InnerText = objModel.ToString();
  • 相关阅读:
    22-Camping野营-露营
    node留言板
    js中const,var,let区别
    app消息推送
    Vue + Mui
    七牛云图片存储---Java
    springboot---发送邮件
    SSM简易版
    Hibernate---快速入门
    Vue---mock.js 使用
  • 原文地址:https://www.cnblogs.com/New-world/p/3168590.html
Copyright © 2011-2022 走看看