文件依赖缓存的运用
发布时间:2020-12-13 20:35:27 所属栏目:百科 来源:网络整理
导读:using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO ; using System.Xml ; using System.Web.Caching ; using System.Threading ; namespace BasicCompent { public class PageCssProvider { static Sy
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO ; using System.Xml ; using System.Web.Caching ; using System.Threading ; namespace BasicCompent { public class PageCssProvider { static System.Web.HttpContext cxt; static ManualResetEvent mr = new ManualResetEvent(true); static ManualResetEvent mw = new ManualResetEvent(true); static XmlDocument _doc; private PageCssProvider() { } static PageCssProvider() { cxt = System.Web.HttpContext.Current; Init(); } public static string PageCss(string pageName) { if (string.IsNullOrEmpty(pageName)) return string.Empty; string xmpath = string.Format("/pages/page[@name=/"{0}/"]",pageName); mw.WaitOne(); mr.Reset(); try { if(_doc ==null ) return string.Empty ; XmlNode node = _doc.SelectSingleNode(xmpath); return node.InnerXml; } finally { mr.Set(); } } static void Init() { mr.WaitOne(); mw.Reset(); try { string realPath = cxt.Server.MapPath("~/Css.xml"); if (!File.Exists(realPath)) return; _doc = new XmlDocument(); _doc.Load(realPath); CacheDependency cd = new CacheDependency(realPath); cxt.Cache.Insert("pageCss",realPath,cd,Cache.NoAbsoluteExpiration,Cache.NoSlidingExpiration,CacheItemPriority.NotRemovable,reportRemovedCallback); } finally { mw.Set(); } } static void reportRemovedCallback(String key,object value,CacheItemRemovedReason reason) { Init(); } } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |