小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

Microsoft Enterprise Library 5.0 系列教程(一) : Caching Application Block (初級)

 goldbomb 2013-09-18

本篇文章具體官方解釋請參照以下鏈接: 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./releases/view/43135

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

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

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

1.下載安裝好MicrosoftEnterprise Library 5.0,然后在運行EntLibConfig.exe

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

  配置屬性說明:

3.  點擊 File 菜單,單擊 Save,保存為一個App.config文件,可以先保存到桌面,之后要用到它. 用記事本打開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)建一個應(yīng)用程序來使用我們配置好的緩存應(yīng)用程序模塊了,在此我創(chuàng)建了一個名為test的控制臺應(yīng)用程序,并將剛才保存的App.config文件拷貝到工程文件夾之下:

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

添加引用:

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

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

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

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

復(fù)制代碼
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();

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

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

//打印
Console.WriteLine(str);
}
}
}
復(fù)制代碼

運行結(jié)果:

7.  移除項目.

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

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

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多