最近偶然看到有朋友在討論asp.net下生成靜態html緩存問題,自己對這方面也算是有點了解,就想着能不能做一個通用的asp.net下通用的生成html的組件。經過了幾個晚上的思考和編碼總算出了這么個東西。 就叫StaticHtml吧。
為了不至於讓大家失去興趣,我先給出一個 “Hello world”首先我們在
web.config,
1:configSections中添加如下內容
<section name="staticHtml" type="StaticHtml.StaticHtmlSection,StaticHtml"/>
2:在 httpModules 節點中加入
<add name="staticnet" type="StaticHtml.HttpModule,StaticHtml"/>
3:最后在configuration節點中加入
<staticHtml>
<rule name="index">
<patten type="StaticHtml.RegexPatten,StaticHtml" pars="RegPatten=index\.aspx"/>
<expire type="StaticHtml.TimeExpire,StaticHtml" pars="Second=300"/>
<genKey type="StaticHtml.UrlMd5GenKey,StaticHtml"/>
<store type="StaticHtml.MemStore,StaticHtml"/>>
</rule>
<rule name="default">
<patten type="StaticHtml.RegexPatten,StaticHtml" pars="RegPatten=.*"/>
<store type="StaticHtml.FileStore,StaticHtml" pars="Path=~/html/"/>
</rule>
</staticHtml>
前面2步的我就不解釋下,相信大家都明白是什么意思。 這里第3步的意思大概是這樣。
首先我們配置了2個生成html緩存的規則,第一個規則名字叫做index,
patten節點: 代表使用正則表達式匹配器,正則表達式是”index\.aspx” 也就是說,url里面包含有index.aspx的頁面
expire節點:代表使用時間過期規則,過了300秒就算過期
genKey節點:代表我們將當前httprequest通過簡單的將url進行md5加密生成一個唯一的key,來標識這個httprequest
store節點: 代表我們使用內存存儲生成的html緩存。
合到一起大概意思是:將url里面包括index.aspx的頁面生成html靜態緩存存到內存里,緩存5分鍾。
至於第二個rule相信大家一看就明白是什么意思了。
我先寫到這里,就當我是做個測試, 雖然在博客園“吸血”很久了, 但還是第一次寫博文,寫的不好,希望大家諒解。 如果大家對這個東西感興趣,
下篇文章我將放出源碼。事實上高手們應該也知道大概是個什么東西….謝謝!