国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開(kāi)通VIP
Microsoft Enterprise Library 5.0 系列教程(一) : Caching Application Block (初級(jí))

本篇文章具體官方解釋請(qǐng)參照以下鏈接: http://msdn.microsoft.com/en-us/library/ff664753%28v=PandP.50%29.aspx

MicrosoftEnterprise Library 5.0下載地址: http://www.microsoft.com/downloads/details.aspx?FamilyId=bcb166f7-dd16-448b-a152-9845760d9b4c&displaylang=en

MicrosoftEnterprise Library 5.0 Documentation : http://entlib.codeplex.com/releases/view/43135

企業(yè)庫(kù)緩存應(yīng)用程序模塊包括了以下特點(diǎn):

  • 可以使用圖形界面對(duì)企業(yè)庫(kù)緩存應(yīng)用程序模塊進(jìn)行配置設(shè)置.
  • 您可以配置一個(gè)持久的存儲(chǔ)單元,或者使用獨(dú)立存儲(chǔ)或企業(yè)庫(kù)數(shù)據(jù)訪問(wèn)應(yīng)用程序模塊, 其狀態(tài)與內(nèi)存中的緩存同步.
  • 管理員可以管理的配置使用組策略工具.
  • 可以通過(guò)創(chuàng)建自定義擴(kuò)展的過(guò)期策略和存儲(chǔ)單元的模塊.
  • 可以保證線程安全.

下面介紹如何使用Microsoft Enterprise Library 5.0中的緩存應(yīng)用程序模塊.

1.下載安裝好MicrosoftEnterprise Library 5.0,然后在運(yùn)行EntLibConfig.exe

2.  選擇Blocks菜單 ,單擊 Add CachingSettings .

  配置屬性說(shuō)明:

3.  點(diǎn)擊 File 菜單,單擊 Save,保存為一個(gè)App.config文件,可以先保存到桌面,之后要用到它. 用記事本打開(kāi)App.config,可以看到如下內(nèi)容.

代碼
<configuration>

<configSections>

<sectionname="cachingConfiguration"type="Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings,Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0,Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true"/>
</configSections>
<cachingConfigurationdefaultCacheManager="Cache Manager">
<cacheManagers>
<addname="Cache Manager"type="Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager,Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0,Culture=neutral, PublicKeyToken=31bf3856ad364e35"
expirationPollFrequencyInSeconds
="60"maximumElementsInCacheBeforeScavenging="1000"
numberToRemoveWhenScavenging
="10" backingStoreName="NullBackingStore"/>
</cacheManagers>
<backingStores>
<addtype="Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.NullBackingStore,Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0,Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name
="NullBackingStore"/>
</backingStores>
</cachingConfiguration>
</configuration>

4.  接著可以創(chuàng)建一個(gè)應(yīng)用程序來(lái)使用我們配置好的緩存應(yīng)用程序模塊了,在此我創(chuàng)建了一個(gè)名為test的控制臺(tái)應(yīng)用程序,并將剛才保存的App.config文件拷貝到工程文件夾之下:

5.  要使用緩存應(yīng)用程序模塊, 需要導(dǎo)入相應(yīng)的Dll文件,在此我們要導(dǎo)入的是Microsoft.Practices.EnterpriseLibrary.Caching.dll ,將App.config文件添加到項(xiàng)目中,并添加Microsoft.Practices.EnterpriseLibrary.Caching和using Microsoft.Practices.EnterpriseLibrary.Caching.Expirations引用:

添加引用:

using Microsoft.Practices.EnterpriseLibrary.Caching;
using Microsoft.Practices.EnterpriseLibrary.Caching.Expirations;

6.  添加和讀取緩存項(xiàng),下方演示的是將一個(gè)string對(duì)象保存到緩存中,在實(shí)際應(yīng)用中我們常常是用于存儲(chǔ)數(shù)據(jù)庫(kù)中讀取出的DataSet的.要注意的是:

(1) 讀取出來(lái)的數(shù)據(jù)要進(jìn)行類型轉(zhuǎn)換為你需要的類型.

(2) 在讀取的時(shí)候最好檢查一下是否為空值.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Practices.EnterpriseLibrary.Caching;
using Microsoft.Practices.EnterpriseLibrary.Caching.Expirations;

namespace test
{
class Program
{
staticvoid Main(string[] args)
{
//創(chuàng)建CacheManager
CacheManager cacheManager = (CacheManager)CacheFactory.GetCacheManager();

//添加緩存項(xiàng)
cacheManager.Add("MyDataReader", "123");

//獲取緩存項(xiàng)
string str = (String)cacheManager.GetData("MyDataReader");

//打印
Console.WriteLine(str);
}
}
}

運(yùn)行結(jié)果:

7.  移除項(xiàng)目.

//移除緩存項(xiàng)
cacheManager.Remove("MyDataReader");

接下來(lái)還要寫緩存應(yīng)用程序模塊的高級(jí)應(yīng)用,請(qǐng)大家關(guān)注,如有錯(cuò)誤的地方也希望大家指出.

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開(kāi)APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Enterprise Library 4.1學(xué)習(xí)筆記4----緩存應(yīng)用程序塊 - 菩提樹下的楊過(guò).Net - 博客園
我心中的核心組件(可插拔的AOP)~第十三回 實(shí)現(xiàn)AOP的攔截組件Unity.Interception
Web.Config配置數(shù)據(jù)庫(kù)連接
EnterpriseLibrary之Caching
企業(yè)庫(kù)中 DatabaseFactory.CreateDatabase 方法創(chuàng)建數(shù)據(jù)庫(kù)實(shí)例的
使用StructureMap擴(kuò)展ASP.NET MVC三層架構(gòu)6
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服