📄 broadcastpollingcachingprovider.cs
字号:
using System;
using System.Collections;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Web;
using System.Web.Caching;
using System.Xml.Serialization;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Framework.Providers;
using DotNetNuke.Services.Exceptions;
//
// DotNetNuke - http://www.dotnetnuke.com
// Copyright (c) 2002-2005
// by Shaun Walker ( sales@perpetualmotion.ca ) of Perpetual Motion Interactive Systems Inc. ( http://www.perpetualmotion.ca )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
namespace DotNetNuke.Services.Cache.BroadcastPollingCachingProvider
{
public class BPCachingProvider : CachingProvider
{
private const string providerType = "caching";
private ProviderConfiguration providerConfiguration;
private static System.Web.Caching.Cache cache;
public BPCachingProvider()
{
providerConfiguration = ProviderConfiguration.GetProviderConfiguration(providerType);
}
private static System.Web.Caching.Cache Cache
{
get
{ //create singleton of the cache object
if (cache == null)
{
cache = HttpRuntime.Cache;
}
return cache;
}
}
#region "Abstract Method Implementation"
public override object Add(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration,
TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback)
{
return Cache.Add(key, value, dependencies, absoluteExpiration, slidingExpiration, priority, onRemoveCallback);
}
public override IDictionaryEnumerator GetEnumerator()
{
return Cache.GetEnumerator();
}
public override object GetItem(string cacheKey)
{
return Cache[cacheKey];
}
public override object GetPersistentCacheItem(string cacheKey, Type type)
{
object obj = Cache[cacheKey];
if (obj != null)
{
return obj;
}
else if (DataCache.CachePersistenceEnabled)
{
Controller controller = new Controller();
obj = controller.GetCachedObject(cacheKey, type);
if (obj != null)
{
Insert(cacheKey, obj, true);
}
}
return obj;
}
public override void Insert (string cacheKey, object obj, bool persistAppRestart)
{
if (persistAppRestart)
{
//remove the cache key which
//will remove the serialized
//file before creating a new one
Remove(cacheKey);
}
Controller controller = new Controller();
if (persistAppRestart && DataCache.CachePersistenceEnabled)
{
controller.AddCachedObject(cacheKey, obj, Globals.ServerName);
controller.AddBroadcast("RemoveCachedItem", cacheKey, Globals.ServerName);
}
else if (Globals.WebFarmEnabled)
{
controller.AddBroadcast("RemoveCachedItem", cacheKey, Globals.ServerName);
}
Cache.Insert(cacheKey, obj);
}
public override void Insert (string cacheKey, object obj, CacheDependency dependency, bool persistAppRestart)
{
if (persistAppRestart)
{
//remove the cache key which
//will remove the serialized
//file before creating a new one
Remove(cacheKey);
}
Controller controller = new Controller();
if (persistAppRestart && DataCache.CachePersistenceEnabled)
{
controller.AddCachedObject(cacheKey, obj, Globals.ServerName);
controller.AddBroadcast("RemoveCachedItem", cacheKey, Globals.ServerName);
}
else if (Globals.WebFarmEnabled)
{
controller.AddBroadcast("RemoveCachedItem", cacheKey, Globals.ServerName);
}
Cache.Insert(cacheKey, obj, dependency);
}
public override void Insert (string cacheKey, object obj, CacheDependency dependency, DateTime absoluteExpiration,
TimeSpan slidingExpiration, bool persistAppRestart)
{
if (persistAppRestart)
{
//remove the cache key which
//will remove the serialized
//file before creating a new one
Remove(cacheKey);
}
Controller controller = new Controller();
if (persistAppRestart && DataCache.CachePersistenceEnabled)
{
controller.AddCachedObject(cacheKey, obj, Globals.ServerName);
controller.AddBroadcast("RemoveCachedItem", cacheKey, Globals.ServerName);
}
else if (Globals.WebFarmEnabled)
{
controller.AddBroadcast("RemoveCachedItem", cacheKey, Globals.ServerName);
}
Cache.Insert(cacheKey, obj, dependency, absoluteExpiration, slidingExpiration);
}
public override void Insert (string cacheKey, object obj, CacheDependency dependency, DateTime absoluteExpiration,
TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback, bool persistAppRestart)
{
if (persistAppRestart)
{
//remove the cache key which
//will remove the serialized
//file before creating a new one
Remove(cacheKey);
}
Controller controller = new Controller();
if (persistAppRestart && DataCache.CachePersistenceEnabled)
{
controller.AddCachedObject(cacheKey, obj, Globals.ServerName);
controller.AddBroadcast("RemoveCachedItem", cacheKey, Globals.ServerName);
}
else if (Globals.WebFarmEnabled)
{
controller.AddBroadcast("RemoveCachedItem", cacheKey, Globals.ServerName);
}
Cache.Insert(cacheKey, obj, dependency, absoluteExpiration, slidingExpiration, priority, onRemoveCallback);
}
public override object Remove(string cacheKey)
{
if (cache[cacheKey] != null)
{
Cache.Remove(cacheKey);
if (Globals.WebFarmEnabled)
{
Controller controller = new Controller();
controller.AddBroadcast("RemoveCachedItem", cacheKey, Globals.ServerName);
}
}
return null;
}
public override void RemovePersistentCacheItem (string cacheKey)
{
if (Cache[cacheKey] != null)
{
Cache.Remove(cacheKey);
if (DataCache.CachePersistenceEnabled)
{
Controller controller = new Controller();
controller.DeleteCachedObject(cacheKey);
controller.AddBroadcast("RemoveCachedItem", cacheKey, Globals.ServerName);
}
}
}
public override string PurgeCache()
{
return "The Broadcast/Polling-Based Caching Provider does not require the PurgeCache feature.";
}
#endregion
#region "Private Methods"
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -