用於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清除應用程序緩存清除提供程序也