首页 > 代码库 > 【缓存】系统缓存全解析 (中)

【缓存】系统缓存全解析 (中)

 

4、应用程序数据缓存

 

   System.Web.Caching 命名空间提供用于缓存服务器上常用数据的类。此命名空间包括 Cache 类,该类是一个字典,您可以在其中存储任意数据对象,如哈希表和数据集。它还为这些对象提供了失效功能,并为您提供了添加和移除这些对象的方法。您还可以添加依赖于其他文件或缓存项的对象,并在从 Cache 对象中移除对象时执行回调以通知应用程序。

 

隐藏行号 复制代码
  1. protected void Page_Load(object sender, EventArgs e)
  2.    {
  3.        string CacheKey = "cachetest";
  4.        object objModel = GetCache(CacheKey);       //从缓存中获取
  5.        if (objModel == null)                       //缓存里没有
  6.        {
  7.            objModel = DateTime.Now;                //把当前时间进行缓存
  8.            if (objModel != null)
  9.            {
  10.                int CacheTime = 30;                 //缓存时间30秒
  11.                SetCache(CacheKey, objModel, DateTime.Now.AddSeconds(CacheTime), TimeSpan.Zero);
  12.            }
  13.        }
  14.        Label1.Text = objModel.ToString();
  15.    }
  16.    #region Cache管理
  17.    /// <summary>
  18.    /// 获取当前应用程序指定CacheKey的Cache对象值
  19.    /// </summary>
  20.    /// <param name="CacheKey">索引键值</param>
  21.    /// <returns>返回缓存对象</returns>
  22.    public static object GetCache(string CacheKey)
  23.    {
  24.        System.Web.Caching.Cache objCache = HttpRuntime.Cache;
  25.        return objCache[CacheKey];
  26.    }
  27.    /// <summary>
  28.    /// 设置当前应用程序指定CacheKey的Cache对象值
  29.    /// </summary>
  30.    /// <param name="CacheKey">索引键值</param>
  31.    /// <param name="objObject">缓存对象</param>
  32.    public static void SetCache(string CacheKey, object objObject)
  33.    {
  34.        System.Web.Caching.Cache objCache = HttpRuntime.Cache;
  35.        objCache.Insert(CacheKey, objObject);
  36.    }
  37.    /// <summary>
  38.    /// 设置当前应用程序指定CacheKey的Cache对象值
  39.    /// </summary>
  40.    /// <param name="CacheKey">索引键值</param>
  41.    /// <param name="objObject">缓存对象</param>
  42.    /// <param name="absoluteExpiration">绝对过期时间</param>
  43.    /// <param name="slidingExpiration">最后一次访问所插入对象时与该对象过期时之间的时间间隔</param>
  44.    public static void SetCache(string CacheKey, object objObject, DateTime absoluteExpiration, TimeSpan slidingExpiration)
  45.    {
  46.        System.Web.Caching.Cache objCache = HttpRuntime.Cache;
  47.        objCache.Insert(CacheKey, objObject, null, absoluteExpiration, slidingExpiration);
  48.    }
  49.    #endregion
<style type="text/css"> .src_container{background-color:#e7e5dc; width:99%; overflow:hidden; margin:12px 0 12px 0 !important; padding:0px 3px 3px 0px} .src_container .titlebar{ background-color:#d4dfff; border:1px solid #4f81bd; border-bottom:0; padding:3px 24px; margin:0; width:auto; line-height:120%; overflow:hidden; text-align:left; font-size:12px} .src_container .toolbar{ display:inline; font-weight:normal; font-size:100%; float:right; cursor:hand; color:#00f; text-align:left; overflow:hidden} .toolbar span.button{ display:inline; font-weight:normal; font-size:100%; cursor:hand; color:#00f; text-align:left; overflow:hidden; cursor:pointer;} .src_container div.clientarea{ background-color:white; border:1px solid #4f81bd; margin:0; width:auto !important; width:100%; height:auto; overflow:auto; text-align:left; font-size:12px; font-family: "Courier New","Consolas","Fixedsys",courier,monospace,serif} .src_container ol.mainarea{ padding:0 0 0 52px; margin:0; background-color:#f7f7ff !important} .number_show{ padding-left:52px !important; list-style:decimal outside !important} .number_show li{ list-style:decimal outside !important; border-left:1px dotted #4f81bd} .number_hide{ padding-left:0px !important; list-style-type:none !important} .number_hide li{ list-style-type:none !important; border-left:0px} ol.mainarea li{ display:list-item !important; font-size:12px !important; margin:0 !important; line-height:18px !important; padding:0 0 0 0px !important; background-color:#f7f7ff !important; color:#4f81bd} ol.mainarea li pre{color:black; line-height:18px; padding:0 0 0 12px !important; margin:0em; background-color:#fff !important} .linewrap ol.mainarea li pre{white-space:pre-wrap; white-space:-moz-pre-wrapwhite-space:-pre-wrap; white-space:-o-pre-wrap; word-wrap:break-word} ol.mainarea li pre.alt{ background-color:#f7f7ff !important} </style><script language="javascript"> function CopyCode(key){var codeElement=null;var trElements=document.all.tags("ol");var i;for(i=0;i<trelements.length;++i){if(key.parentelement.parentelement.parentelement==trelements[i].parentelement.parentelement){codeelement=trelements[i];break}}if(codeelement!=null){var content="codeElement.innerText;if(window.clipboardData=http://www.mamicode.com/=null){window.alert(" 您的浏览器不支持脚本复制,请尝试手动复制。")}else{window.clipboardData.setData("Text",content);window.alert("源代码已经复制到剪贴板上。")}}}function" LineNumberVisible(key){var codeelement="null;var" trelements="document.all.tags(" ol");var" i;for( i="0;i<trElements.length;++i){if(key.parentElement.parentElement.parentElement==trElements[i].parentElement.parentElement){codeElement=trElements[i];break}}if(codeElement!=null){if(codeElement.className==" mainarea" number_hide"){codeElement. classname="mainarea number_show" ;key. innertext="隐藏行号" }else{codeElement. classname="mainarea number_hide" ;key. innertext="显示行号" }}}function ChangeIcon(key,isHover){if(isHover)key.style. color=‘red‘ ;else key.style. color=‘blue‘ }function CopyCode_CheckKey(key){if(window.event. keycode="=13)CopyCode(key)}function" AboutMe(){window.alert("本代码框由 CodePaste for Windows Live Writer 生成。\r\n\r\nAuthor: 范传根\r\nEmail: chuangen@live.cn\r\nWebsite: http://chuangen.name\r\nBlog: http://blog.csdn.net/chuangen");} </script>

 

Cache  Insert 方法 (String, Object, CacheDependency, DateTime, TimeSpan, CacheItemPriority, CacheItemRemovedCallback)

<style type="text/css"> .src_container{background-color:#e7e5dc; width:99%; overflow:hidden; margin:12px 0 12px 0 !important; padding:0px 3px 3px 0px} .src_container .titlebar{ background-color:#d4dfff; border:1px solid #4f81bd; border-bottom:0; padding:3px 24px; margin:0; width:auto; line-height:120%; overflow:hidden; text-align:left; font-size:12px} .src_container .toolbar{ display:inline; font-weight:normal; font-size:100%; float:right; cursor:hand; color:#00f; text-align:left; overflow:hidden} .toolbar span.button{ display:inline; font-weight:normal; font-size:100%; cursor:hand; color:#00f; text-align:left; overflow:hidden; cursor:pointer;} .src_container div.clientarea{ background-color:white; border:1px solid #4f81bd; margin:0; width:auto !important; width:100%; height:auto; overflow:auto; text-align:left; font-size:12px; font-family: "Courier New","Consolas","Fixedsys",courier,monospace,serif} .src_container ol.mainarea{ padding:0 0 0 52px; margin:0; background-color:#f7f7ff !important} .number_show{ padding-left:52px !important; list-style:decimal outside !important} .number_show li{ list-style:decimal outside !important; border-left:1px dotted #4f81bd} .number_hide{ padding-left:0px !important; list-style-type:none !important} .number_hide li{ list-style-type:none !important; border-left:0px} ol.mainarea li{ display:list-item !important; font-size:12px !important; margin:0 !important; line-height:18px !important; padding:0 0 0 0px !important; background-color:#f7f7ff !important; color:#4f81bd} ol.mainarea li pre{color:black; line-height:18px; padding:0 0 0 12px !important; margin:0em; background-color:#fff !important} .linewrap ol.mainarea li pre{white-space:pre-wrap; white-space:-moz-pre-wrapwhite-space:-pre-wrap; white-space:-o-pre-wrap; word-wrap:break-word} ol.mainarea li pre.alt{ background-color:#f7f7ff !important}</style><script language="javascript"> function CopyCode(key){var codeElement=null;var trElements=document.all.tags("ol");var i;for(i=0;i<trelements.length;++i){if(key.parentelement.parentelement.parentelement==trelements[i].parentelement.parentelement){codeelement=trelements[i];break}}if(codeelement!=null){var content="codeElement.innerText;if(window.clipboardData=http://www.mamicode.com/=null){window.alert(" 您的浏览器不支持脚本复制,请尝试手动复制。")}else{window.clipboardData.setData("Text",content);window.alert("源代码已经复制到剪贴板上。")}}}function" LineNumberVisible(key){var codeelement="null;var" trelements="document.all.tags(" ol");var" i;for( i="0;i<trElements.length;++i){if(key.parentElement.parentElement.parentElement==trElements[i].parentElement.parentElement){codeElement=trElements[i];break}}if(codeElement!=null){if(codeElement.className==" mainarea" number_hide"){codeElement. classname="mainarea number_show" ;key. innertext="隐藏行号" }else{codeElement. classname="mainarea number_hide" ;key. innertext="显示行号" }}}function ChangeIcon(key,isHover){if(isHover)key.style. color=‘red‘ ;else key.style. color=‘blue‘ }function CopyCode_CheckKey(key){if(window.event. keycode="=13)CopyCode(key)}function" AboutMe(){window.alert("本代码框由 CodePaste for Windows Live Writer 生成。\r\n\r\nAuthor: 范传根\r\nEmail: chuangen@live.cn\r\nWebsite: http://chuangen.name\r\nBlog: http://blog.csdn.net/chuangen");} </script>
public void Insert(    string key,      //需要添加到Cache中的键
Object value, //对应的值
CacheDependency dependencies, //缓存依赖项 null
DateTime absoluteExpiration, //固定缓存时间 DateTime.Now.AddMinutes(1) TimeSpan slidingExpiration, //可到延时缓存时间 System.Web.Caching.Cache.NoSlidingExpiration CacheItemPriority priority, //缓存中的优先级 System.Web.Caching.CacheItemPriority.NotRemovable CacheItemRemovedCallback onRemoveCallback //移除时调用的回调函数 new System.Web.Caching.CacheItemRemovedCallback(OnMoveCacheBack));)
 
技术分享

 

System.Web.Caching.Cache  Insert和Add区别

            Add方法

 

                    object Add(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback);

 

      Insert方法

 

                    void Insert(string key, object value);

                    void Insert(string key, object value, CacheDependency dependencies);

                    void Insert(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration);

                    void Insert(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemUpdateCallback onUpdateCallback);

                    void Insert(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback);

        

         比较、区别

               a).     Insert方法支持5种重载,使用灵活,而Add方法必须提供7个参数;

               b).     Add方法可以返回缓存项的数据对象,Insert 返回Void;

               c).     添加重复缓存情况下,Insert会替换该项,而Add方法会报错。

 

5、文件缓存依赖

    这种策略让缓存依赖于一个指定的文件,通过改变文件的更新日期来清除缓存。

 

隐藏行号 复制代码
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3.     string CacheKey = "cachetest";
  4.     object objModel = GetCache(CacheKey);//从缓存中获取
  5.     if (objModel == null) //缓存里没有
  6.     {
  7.         objModel = DateTime.Now;//把当前时间进行缓存
  8.         if (objModel != null)
  9.         {
  10.             //依赖 C:\\test.txt 文件的变化来更新缓存
  11.             System.Web.Caching.CacheDependency dep = new System.Web.Caching.CacheDependency("C:\\test.txt");
  12.             SetCache(CacheKey, objModel, dep);//写入缓存
  13.         }
  14.     }
  15.     Label1.Text = objModel.ToString();
  16. }
  17. #region 缓存管理
  18. /// <summary>
  19. /// 获取当前应用程序指定CacheKey的Cache对象值
  20. /// </summary>
  21. /// <param name="CacheKey">索引键值</param>
  22. /// <returns>返回缓存对象</returns>
  23. public static object GetCache(string CacheKey)
  24. {
  25.     System.Web.Caching.Cache objCache = HttpRuntime.Cache;
  26.     return objCache[CacheKey];
  27. }
  28. /// <summary>
  29. /// 设置以缓存依赖的方式缓存数据
  30. /// </summary>
  31. /// <param name="CacheKey">索引键值</param>
  32. /// <param name="objObject">缓存对象</param>
  33. /// <param name="cacheDepen">依赖对象</param>
  34. public static void SetCache(string CacheKey, object objObject, System.Web.Caching.CacheDependency dep)
  35. {
  36.     System.Web.Caching.Cache objCache = HttpRuntime.Cache;
  37.     objCache.Insert(
  38.         CacheKey,
  39.         objObject,
  40.         dep,
  41.         System.Web.Caching.Cache.NoAbsoluteExpiration, //从不过期
  42.         System.Web.Caching.Cache.NoSlidingExpiration, //禁用可调过期
  43.         System.Web.Caching.CacheItemPriority.Default,
  44.         null);
  45. }
  46. #endregion
<style type="text/css"> .src_container{background-color:#e7e5dc; width:99%; overflow:hidden; margin:12px 0 12px 0 !important; padding:0px 3px 3px 0px} .src_container .titlebar{ background-color:#d4dfff; border:1px solid #4f81bd; border-bottom:0; padding:3px 24px; margin:0; width:auto; line-height:120%; overflow:hidden; text-align:left; font-size:12px} .src_container .toolbar{ display:inline; font-weight:normal; font-size:100%; float:right; cursor:hand; color:#00f; text-align:left; overflow:hidden} .toolbar span.button{ display:inline; font-weight:normal; font-size:100%; cursor:hand; color:#00f; text-align:left; overflow:hidden; cursor:pointer;} .src_container div.clientarea{ background-color:white; border:1px solid #4f81bd; margin:0; width:auto !important; width:100%; height:auto; overflow:auto; text-align:left; font-size:12px; font-family: "Courier New","Consolas","Fixedsys",courier,monospace,serif} .src_container ol.mainarea{ padding:0 0 0 52px; margin:0; background-color:#f7f7ff !important} .number_show{ padding-left:52px !important; list-style:decimal outside !important} .number_show li{ list-style:decimal outside !important; border-left:1px dotted #4f81bd} .number_hide{ padding-left:0px !important; list-style-type:none !important} .number_hide li{ list-style-type:none !important; border-left:0px} ol.mainarea li{ display:list-item !important; font-size:12px !important; margin:0 !important; line-height:18px !important; padding:0 0 0 0px !important; background-color:#f7f7ff !important; color:#4f81bd} ol.mainarea li pre{color:black; line-height:18px; padding:0 0 0 12px !important; margin:0em; background-color:#fff !important} .linewrap ol.mainarea li pre{white-space:pre-wrap; white-space:-moz-pre-wrapwhite-space:-pre-wrap; white-space:-o-pre-wrap; word-wrap:break-word} ol.mainarea li pre.alt{ background-color:#f7f7ff !important} </style><script language="javascript"> function CopyCode(key){var codeElement=null;var trElements=document.all.tags("ol");var i;for(i=0;i<trelements.length;++i){if(key.parentelement.parentelement.parentelement==trelements[i].parentelement.parentelement){codeelement=trelements[i];break}}if(codeelement!=null){var content="codeElement.innerText;if(window.clipboardData=http://www.mamicode.com/=null){window.alert(" 您的浏览器不支持脚本复制,请尝试手动复制。")}else{window.clipboardData.setData("Text",content);window.alert("源代码已经复制到剪贴板上。")}}}function" LineNumberVisible(key){var codeelement="null;var" trelements="document.all.tags(" ol");var" i;for( i="0;i<trElements.length;++i){if(key.parentElement.parentElement.parentElement==trElements[i].parentElement.parentElement){codeElement=trElements[i];break}}if(codeElement!=null){if(codeElement.className==" mainarea" number_hide"){codeElement. classname="mainarea number_show" ;key. innertext="隐藏行号" }else{codeElement. classname="mainarea number_hide" ;key. innertext="显示行号" }}}function ChangeIcon(key,isHover){if(isHover)key.style. color=‘red‘ ;else key.style. color=‘blue‘ }function CopyCode_CheckKey(key){if(window.event. keycode="=13)CopyCode(key)}function" AboutMe(){window.alert("本代码框由 CodePaste for Windows Live Writer 生成。\r\n\r\nAuthor: 范传根\r\nEmail: chuangen@live.cn\r\nWebsite: http://chuangen.name\r\nBlog: http://blog.csdn.net/chuangen");} </script>

 

当我们改变test.txt的内容时,缓存会自动更新。这种方式非常适合读取配置文件的缓存处理。如果配置文件不变化,就一直读取缓存的信息,一旦配置发生变化,自动更新同步缓存的数据。

 

这种方式的缺点是,如果缓存的数据比较多,相关的依赖文件比较松散,对管理这些依赖文件有一定的麻烦。对于负载均衡环境下,还需要同时更新多台Web服务器下的缓存文件,如果多个Web应用中的缓存依赖于同一个共享的文件,可能会省掉这个麻烦。

 

如何:从缓存中移除项时通知应用程序

 

在大多数缓存方案中,当从缓存中移除一个项时,不必通知您该项已被移除。典型的开发模式是在使用项之前始终检查该项是否已在缓存中。如果项位于缓存中,则可以使用。如果不在缓存中,则应再次检索该项,然后将其添加回缓存。

 

但是,在某些情况下,如果从缓存中移除项时通知应用程序,可能非常有用。例如,您可能希望跟踪从缓存中移除项的时间和原因,以便对缓存设置进行调整。

 

为了在从缓存中移除项时能够发出通知,ASP.NET 提供了 CacheItemRemovedCallback 委托。 该委托为事件处理程序定义签名,以便在从缓存中移除项时调用该事件处理程序。通常,可通过在管理缓存数据的业务对象中创建一个处理程序来实现回调。

 

示例

 

下面的示例将演示一个名为 ReportManager 的类。 此类的 GetReport 方法会创建一个由字符串“Report Text”组成的报告。 该方法将此报告保存在缓存中,在随后调用该方法时,它将从缓存中检索此报告。

 

如果两次调用 GetReport 的时间间隔超过 15 秒,则 ASP.NET 将会从缓存中移除此报告。 当发生该事件时,将调用 ReportManager 类的 ReportRemovedCallback 方法。 此方法将私有成员变量设置为“Re-created [date and time]”,其中 [date and time] 为当前的日期和时间。 下一次调用 GetReport 时(在缓存项到期之后),该方法将重新创建报告,并将 ReportRemovedCallback 方法设置的变量值追加到该报告中。 ShowReport.aspx 页会显示 GetReport 返回的报告字符串,其中包括最后一次重新创建报告的日期和时间。

 

若要查看此行为,请加载该页面并等待,15 秒过后,再在浏览器中重新加载该页面。您将看到添加到报告文本中的日期和时间。

 

隐藏行号 复制代码
  1. using System;
  2. using System.Text;
  3. using System.Web;
  4. using System.Web.Caching;
  5. public static class ReportManager
  6. {
  7.     private static string _lastRemoved = "";
  8.     public static String GetReport()
  9.     {
  10.         string report = HttpRuntime.Cache["MyReport"] as string;
  11.         if (report == null)
  12.         {
  13.             report = GenerateAndCacheReport();
  14.         }
  15.         return report;
  16.     }
  17.     private static string GenerateAndCacheReport()
  18.     {
  19.         string report = "Report Text. " + _lastRemoved.ToString();
  20.         HttpRuntime.Cache.Insert(
  21.             "MyReport",
  22.             report,
  23.             null,
  24.             Cache.NoAbsoluteExpiration,
  25.             new TimeSpan(0, 0, 15),
  26.             CacheItemPriority.Default,
  27.             new CacheItemRemovedCallback(ReportRemovedCallback));
  28.         return report;
  29.     }
  30.     public static void ReportRemovedCallback(String key, object value,
  31.         CacheItemRemovedReason removedReason)
  32.     {
  33.         _lastRemoved = "Re-created " + DateTime.Now.ToString();
  34.     }
  35. }
<style type="text/css"> .src_container{background-color:#e7e5dc; width:99%; overflow:hidden; margin:12px 0 12px 0 !important; padding:0px 3px 3px 0px} .src_container .titlebar{ background-color:#d4dfff; border:1px solid #4f81bd; border-bottom:0; padding:3px 24px; margin:0; width:auto; line-height:120%; overflow:hidden; text-align:left; font-size:12px} .src_container .toolbar{ display:inline; font-weight:normal; font-size:100%; float:right; cursor:hand; color:#00f; text-align:left; overflow:hidden} .toolbar span.button{ display:inline; font-weight:normal; font-size:100%; cursor:hand; color:#00f; text-align:left; overflow:hidden; cursor:pointer;} .src_container div.clientarea{ background-color:white; border:1px solid #4f81bd; margin:0; width:auto !important; width:100%; height:auto; overflow:auto; text-align:left; font-size:12px; font-family: "Courier New","Consolas","Fixedsys",courier,monospace,serif} .src_container ol.mainarea{ padding:0 0 0 52px; margin:0; background-color:#f7f7ff !important} .number_show{ padding-left:52px !important; list-style:decimal outside !important} .number_show li{ list-style:decimal outside !important; border-left:1px dotted #4f81bd} .number_hide{ padding-left:0px !important; list-style-type:none !important} .number_hide li{ list-style-type:none !important; border-left:0px} ol.mainarea li{ display:list-item !important; font-size:12px !important; margin:0 !important; line-height:18px !important; padding:0 0 0 0px !important; background-color:#f7f7ff !important; color:#4f81bd} ol.mainarea li pre{color:black; line-height:18px; padding:0 0 0 12px !important; margin:0em; background-color:#fff !important} .linewrap ol.mainarea li pre{white-space:pre-wrap; white-space:-moz-pre-wrapwhite-space:-pre-wrap; white-space:-o-pre-wrap; word-wrap:break-word} ol.mainarea li pre.alt{ background-color:#f7f7ff !important} </style><script language="javascript"> function CopyCode(key){var codeElement=null;var trElements=document.all.tags("ol");var i;for(i=0;i<trelements.length;++i){if(key.parentelement.parentelement.parentelement==trelements[i].parentelement.parentelement){codeelement=trelements[i];break}}if(codeelement!=null){var content="codeElement.innerText;if(window.clipboardData=http://www.mamicode.com/=null){window.alert(" 您的浏览器不支持脚本复制,请尝试手动复制。")}else{window.clipboardData.setData("Text",content);window.alert("源代码已经复制到剪贴板上。")}}}function" LineNumberVisible(key){var codeelement="null;var" trelements="document.all.tags(" ol");var" i;for( i="0;i<trElements.length;++i){if(key.parentElement.parentElement.parentElement==trElements[i].parentElement.parentElement){codeElement=trElements[i];break}}if(codeElement!=null){if(codeElement.className==" mainarea" number_hide"){codeElement. classname="mainarea number_show" ;key. innertext="隐藏行号" }else{codeElement. classname="mainarea number_hide" ;key. innertext="显示行号" }}}function ChangeIcon(key,isHover){if(isHover)key.style. color=‘red‘ ;else key.style. color=‘blue‘ }function CopyCode_CheckKey(key){if(window.event. keycode="=13)CopyCode(key)}function" AboutMe(){window.alert("本代码框由 CodePaste for Windows Live Writer 生成。\r\n\r\nAuthor: 范传根\r\nEmail: chuangen@live.cn\r\nWebsite: http://chuangen.name\r\nBlog: http://blog.csdn.net/chuangen");} </script>
隐藏行号 复制代码
  1. <%@ Page Language="C#" AutoEventWireup="true" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head id="Head1" runat="server">
  5.     <title></title>
  6. </head>
  7. <body>
  8.     <form id="form1" runat="server">
  9.     <div>
  10.     <%=ReportManager.GetReport() %>
  11.     </div>
  12.     </form>
  13. </body>
  14. </html>
<style type="text/css"> .src_container{background-color:#e7e5dc; width:99%; overflow:hidden; margin:12px 0 12px 0 !important; padding:0px 3px 3px 0px} .src_container .titlebar{ background-color:#d4dfff; border:1px solid #4f81bd; border-bottom:0; padding:3px 24px; margin:0; width:auto; line-height:120%; overflow:hidden; text-align:left; font-size:12px} .src_container .toolbar{ display:inline; font-weight:normal; font-size:100%; float:right; cursor:hand; color:#00f; text-align:left; overflow:hidden} .toolbar span.button{ display:inline; font-weight:normal; font-size:100%; cursor:hand; color:#00f; text-align:left; overflow:hidden; cursor:pointer;} .src_container div.clientarea{ background-color:white; border:1px solid #4f81bd; margin:0; width:auto !important; width:100%; height:auto; overflow:auto; text-align:left; font-size:12px; font-family: "Courier New","Consolas","Fixedsys",courier,monospace,serif} .src_container ol.mainarea{ padding:0 0 0 52px; margin:0; background-color:#f7f7ff !important} .number_show{ padding-left:52px !important; list-style:decimal outside !important} .number_show li{ list-style:decimal outside !important; border-left:1px dotted #4f81bd} .number_hide{ padding-left:0px !important; list-style-type:none !important} .number_hide li{ list-style-type:none !important; border-left:0px} ol.mainarea li{ display:list-item !important; font-size:12px !important; margin:0 !important; line-height:18px !important; padding:0 0 0 0px !important; background-color:#f7f7ff !important; color:#4f81bd} ol.mainarea li pre{color:black; line-height:18px; padding:0 0 0 12px !important; margin:0em; background-color:#fff !important} .linewrap ol.mainarea li pre{white-space:pre-wrap; white-space:-moz-pre-wrapwhite-space:-pre-wrap; white-space:-o-pre-wrap; word-wrap:break-word} ol.mainarea li pre.alt{ background-color:#f7f7ff !important} </style><script language="javascript"> function CopyCode(key){var codeElement=null;var trElements=document.all.tags("ol");var i;for(i=0;i<trElements.length;++i){if(key.parentElement.parentElement.parentElement==trElements[i].parentElement.parentElement){codeElement=trElements[i];break}}if(codeElement!=null){var content=codeElement.innerText;if(window.clipboardData=http://www.mamicode.com/=null){window.alert("您的浏览器不支持脚本复制,请尝试手动复制。")}else{window.clipboardData.setData("Text",content);window.alert("源代码已经复制到剪贴板上。")}}}function LineNumberVisible(key){var codeElement=null;var trElements=document.all.tags("ol");var i;for(i=0;i<trElements.length;++i){if(key.parentElement.parentElement.parentElement==trElements[i].parentElement.parentElement){codeElement=trElements[i];break}}if(codeElement!=null){if(codeElement.className=="mainarea number_hide"){codeElement.className="mainarea number_show";key.innerText="隐藏行号"}else{codeElement.className="mainarea number_hide";key.innerText="显示行号"}}}function ChangeIcon(key,isHover){if(isHover)key.style.color=‘red‘;else key.style.color=‘blue‘}function CopyCode_CheckKey(key){if(window.event.keyCode==13)CopyCode(key)}function AboutMe(){window.alert("本代码框由 CodePaste for Windows Live Writer 生成。\r\n\r\nAuthor: 范传根\r\nEmail: chuangen@live.cn\r\nWebsite: http://chuangen.name\r\nBlog: http://blog.csdn.net/chuangen");} </script>

【缓存】系统缓存全解析 (中)