zoukankan      html  css  js  c++  java
  • 做了一个缓存文件依赖

            private string DependencyDirectory = System.Web.HttpContext.Current.Server.MapPath("~/FileCacheDependency");
            private string DependencyFile = System.Web.HttpContext.Current.Server.MapPath("~/FileCacheDependency") + "\\DependencyFile" ;
            private string AuthorizationCacheKey = "AuthorizationCacheKey";
           

     
            public void UpdateDependency()
            {
                if (System.IO.File.Exists(DependencyFile))
                {
                    FileInfo FI = new FileInfo(DependencyFile);
                    StreamWriter SW = FI.AppendText();
                    SW.WriteLine(Guid.NewGuid().ToString());
                    SW.Close();
                }
            }


            private void CreateDependency()
            {
                if (!Directory.Exists(DependencyDirectory))
                {
                    Directory.CreateDirectory(DependencyDirectory);
                }
                if (!File.Exists(DependencyFile))
                {
                    FileStream fs = File.Create(DependencyFile);
                    fs.Close();
                }
            }


            public void AddOperationAuthorization(Object Obj)
            {
                CreateDependency();
                CacheDependency CD = new CacheDependency(DependencyFile);
                CacheService.InsertCache(AuthorizationCacheKey, Obj, CD);
            }

     
            private static bool InsertCachePrivate(string CacheKey, object CacheInfo, CacheDependency CD, CacheItemRemovedCallback CallBack)
            {
                if (CacheKey != null && CacheKey.Length != 0 && CacheInfo != null)
                {

                    HttpContext.Current.Cache.Insert(CacheKey, CacheInfo, CD,
                        System.DateTime.Now.AddSeconds(300),
                        System.Web.Caching.Cache.NoSlidingExpiration,
                        System.Web.Caching.CacheItemPriority.Default,
                        CallBack);
                    return true;
                }
                else
                {
                    return false;
                }
            }


            public static bool InsertCache(string CacheKey, object CacheInfo, CacheDependency CD)
            {
                CacheItemRemovedCallback CallBackPrivate = new CacheItemRemovedCallback(onRemove);
                return InsertCachePrivate(CacheKey, CacheInfo, CD, CallBackPrivate);
            }


            private static void onRemove(string IdentifyCode, object CacheInfo, CacheItemRemovedReason reason)
            {

            }

  • 相关阅读:
    【PS技巧】常用概念和功能操作
    【存储】RAID磁盘阵列选择
    【Python 01】Python一种面向对象、解释型计算机程序设计语言
    【PS技巧】如何校正倾斜的图片
    【阿里巴巴大数据实践笔记】第14章:存储和成本管理
    【阿里巴巴大数据实践笔记】第13章:计算管理
    【阿里巴巴大数据实践笔记】第9章:阿里巴巴数据整合及管理体系
    今晚直播丨抢鲜体验-openGauss入门
    详述一则数据库死锁故障的分析过程
    前端学习笔记(一)HTML入门
  • 原文地址:https://www.cnblogs.com/cuihongyu3503319/p/1330051.html
Copyright © 2011-2022 走看看