用于Windows Server AppFabric 1.0的asp.net输出缓存提供程序是否存在?用于asp.net输出缓存的Windows Server Appfabric提供程序
0
A
回答
2
不,但是由于输出缓存可在ASP.NET 4.0中插入(使用提供者模型),因此您可以编写自己的代码。
要创建一个新的输出缓存提供程序,您需要继承System.Web.Caching.OutputCacheProvider
,那么需要引用System.Web
和System.Configuration
。
然后,它主要是覆盖基本提供者的四个方法,即添加,获取,删除和设置的情况。由于您的网站可能会获得不少点击量,因此您一定要使用Singleton作为DataCacheFactory,此代码使用Jon Skeet's singleton pattern(假设我已正确理解)。
using System;
using System.Web.Caching;
using Microsoft.ApplicationServer.Caching;
namespace AppFabricOutputCache
{
public sealed class AppFabricOutputCacheProvider : OutputCacheProvider
{
private static readonly AppFabricOutputCacheProvider instance = new AppFabricOutputCacheProvider();
private DataCacheFactory factory;
private DataCache cache;
static AppFabricOutputCacheProvider()
{ }
private AppFabricOutputCacheProvider()
{
// Constructor - new up the factory and get a reference to the cache based
// on a setting in web.config
factory = new DataCacheFactory();
cache = factory.GetCache(System.Web.Configuration.WebConfigurationManager.AppSettings["OutputCacheName"]);
}
public static AppFabricOutputCacheProvider Instance
{
get { return instance; }
}
public override object Add(string key, object entry, DateTime utcExpiry)
{
// Add an object into the cache.
// Slight disparity here in that we're passed an absolute expiry but AppFabric wants
// a TimeSpan. Subtract Now from the expiry we get passed to create the TimeSpan
cache.Add(key, entry, utcExpiry - DateTime.UtcNow);
}
public override object Get(string key)
{
return cache.Get(key);
}
public override void Remove(string key)
{
cache.Remove(key);
}
public override void Set(string key, object entry, DateTime utcExpiry)
{
// Set here means 'add it if it doesn't exist, update it if it does'
// We can do this by using the AppFabric Put method
cache.Put(key, entry, utcExpiry - DateTime.UtcNow);
}
}
}
一旦你得到了这个写的,你需要配置你的应用程序在你的web.config使用它:
<system.web>
<caching>
<outputCache defaultProvider="AppFabricOutputCache">
<providers>
<add name="AppFabricOutputCache" type="AppFabricOutputCache, AppFabricOutputCacheProvider" />
</providers>
</outputCache>
</caching>
</system.web>
MSDN: OutputCacheProvider
ScottGu's blog on creating OutputCacheProviders
相关问题
- 1. AppFabric用于缓存
- 2. 基于Windows Server AppFabric缓存超时的无效回调
- 3. AppFabric缓存传输安全
- 4. 自定义输出缓存提供程序
- 5. Windows服务器AppFabric缓存
- 6. ASP.Net会话状态的AppFabric Cache提供程序是否允许支持存储?
- 7. Windows Server AppFabric缓存的Windows版本要求
- 8. 的Windows Server AppFabric的自定义配置提供者发布
- 9. 用于Redis缓存和TTL的ASP.NET会话状态提供程序
- 10. Windows Server AppFabric缓存可以与IIS Express for ASP.NET Session一起使用吗?
- 11. AppFabric 1.1缓存(崩溃的Windows服务)
- 12. ASP.NET输出缓存vs ASP.NET对象缓存
- 13. Windows Server AppFabric高速缓存会话存储
- 14. 在ASP.NET MVC中使用Azure AppFabric缓存
- 15. ASP.NET随机缓存输出
- 16. Appfabric缓存 - 序列化
- 17. ASP.net页面输出缓存
- 18. 是否有关于使用.NET 4.0可扩展输出缓存配置AppFabric缓存的分步教程?
- 19. 错误而配置的Windows Server AppFabric中的XML(如缓存服务配置提供商)
- 20. 支持流式传输的.NET缓存提供程序?
- 21. Appfabric缓存maxconnectionstoserver
- 22. NHibernate + AppFabric缓存
- 23. AppFabric缓存错误
- 24. Windows Server AppFabric缓存和数据库同步
- 25. 无法在Windows Server Appfabric中创建缓存
- 26. 基于域的ASP.net MVC 3输出缓存
- 27. ProviderException使用自定义的输出缓存提供RedisOutputCacheProvider
- 28. Azure AppFabric与Server AppFabric - 今天
- 29. 开发.net MVC3应用程序使用AppFabric 1.1进行缓存
- 30. Android清除应用程序缓存清除提供程序也