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();
  • 相关阅读:
    Windows打开文件后提示,文件或目录损坏无法读取。
    windows10 提示内存不足
    配置Redis集群为开机自启动
    Hbase的rowkey设计
    Hbase表类型的设计
    mycat的下载和安装
    mycat简介
    mysql|tomcat|nginx|redis在docker中的部署
    docker的备份和迁移
    Redis Cluster集群详介绍和伪集群搭建
  • 原文地址:https://www.cnblogs.com/New-world/p/3168590.html
Copyright © 2011-2022 走看看