Is there a step-by-step tutorial for configuring AppFabric Caching with .NET 4.0 Extensible Output Caching?
I want to use AppFabric (Velocity) as the Disk Caching Provider to work with ASP.NET 4.0's extensible output caching feature. But when I installed the AppFabric, I found it is incredibly hard to configure and I have no idea how can I make my ASP.NET ap开发者_运维百科p to work with it. So I was wondering is there a easy to understand tutorial for configuring both?
Or, is there any easier way other than AppFarbric to implement disk caching with ASP.NET?
I wrote some VB code for an AppFabricOutputCacheProvider in January - it's on my blog here. A C# (4.0) version would be:
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;
}
}
}
To use this in your application, you need this in your web.config.
<caching>
<outputCache>
<providers>
<add name="AppFabricOutputCacheProvider" type="AppFabricOutputCache.CacheProvider"/>
</providers>
</outputCache>
</caching>
Gunnar Peipman has a disk-based output cache provider on his blog here.
精彩评论