2010-05-04 19 views
1

我想使用AppFabric(Velocity)作爲磁盤緩存提供程序來使用ASP.NET 4.0的可擴展輸出緩存功能。但是當我安裝AppFabric時,我發現配置非常困難,我不知道如何讓我的ASP.NET應用程序能夠使用它。所以我想知道是否有一個易於理解的教程配置兩者?是否有關於使用.NET 4.0可擴展輸出緩存配置AppFabric緩存的分步教程?

或者,除了AppFarbric之外,還有其他更簡單的方法來實現ASP.NET的磁盤緩存嗎?

+0

AppFabric可能有點混亂配置。有什麼需要幫助的嗎? – PhilPursglove 2010-05-05 07:20:17

回答

0

我在1月份爲AppFabricOutputCacheProvider寫了一些VB代碼 - 它在我的博客here上。一個C#(4.0)版本將是:

using System.Web; 
using Microsoft.ApplicationServer.Caching; 

namespace AppFabricOutputCache 
{ 
    public class CacheProvider: System.Web.Caching.OutputCacheProvider, IDisposable 
    { 
     DataCache mCache; 

     const String OutputCacheName = "OutputCache"; 

     public void New() 
     { 
      DataCacheFactory factory; 

      factory = new DataCacheFactory(); 

      mCache = factory.GetCache(OutputCacheName); 
     } 

     public override Object Add(String key, Object entry, DateTime utcExpiry) 
     { 
      mCache.Add(key, entry, utcExpiry - DateTime.UtcNow); 

      return entry; 
     } 

     public override object Get(string key) 
     { 
      return mCache.Get(key); 
     } 

     public override void Remove(string key) 
     { 
      mCache.Remove(key); 
     } 

     public override void Set(string key, object entry, DateTime utcExpiry) 
     { 
      mCache.Put(key, entry, utcExpiry - DateTime.UtcNow); 
     } 

     public void IDisposable.Dispose() 
     { 
      mCache = null; 
     } 

    } 
} 

要在您的應用程序中使用它,您需要在您的web.config中。

<caching> 
    <outputCache> 
    <providers> 
     <add name="AppFabricOutputCacheProvider" type="AppFabricOutputCache.CacheProvider"/> 
    </providers> 
    </outputCache> 
</caching> 

貢納爾Peipman在他的博客here基於磁盤的輸出緩存提供商。

+0

嗨菲爾,謝謝你的回答!我剛看到另一個解決方案:http://bit.ly/22wknT 你知道哪種解決方案更快嗎? (我只在我的本地服務器上存儲緩存,沒有分佈式存儲需要) – silent 2010-05-05 20:40:15

+0

很難說沒有測試它,但我期望* AppFabric會有邊緣,因爲它全部在內存中完成,基於磁盤的緩存很可能訪問磁盤有一些延遲。 – PhilPursglove 2010-05-06 09:44:32