我想使用 AppFabric (Velocity) 作为磁盘缓存提供程序来使用 ASP.NET 4.0 的可扩展输出缓存功能。但是当我安装 AppFabric 时,我发现配置起来非常困难,而且我不知道如何让我的 ASP.NET 应用程序与它一起工作。所以我想知道是否有一个易于理解的教程来配置两者?
或者,除了 AppFarbric 之外,还有其他更简单的方法可以使用 ASP.NET 实现磁盘缓存吗?
我在一月份为 AppFabricOutputCacheProvider 编写了一些 VB 代码 - 它在我的博客上。AC# (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>
Gunnar Peipman 在他的博客上提供了一个基于磁盘的输出缓存提供程序。