📄 datacache.cs
字号:
using System;
using System.Collections;
using System.Configuration;
using System.Web;
using System.Web.Caching;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Services.Cache;
//
// 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.Common.Utilities
{
public enum CoreCacheType
{
Host = 1,
Portal = 2,
Tab = 3
}
public class DataCache
{
public static bool CachePersistenceEnabled
{
get
{
if (ConfigurationSettings.AppSettings["EnableCachePersistence"] != null)
{
if (ConfigurationSettings.AppSettings["EnableCachePersistence"] == "true")
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
}
public static object GetCache(string cacheKey)
{
return CachingProvider.Instance().GetItem(cacheKey);
}
public static object GetPersistentCacheItem(string cacheKey, Type type)
{
return CachingProvider.Instance().GetPersistentCacheItem(cacheKey, type);
}
public static void SetCache (string cacheKey, object o)
{
SetCache(cacheKey, o, false);
}
public static void SetCache (string cacheKey, object o, bool persistAppRestart)
{
CachingProvider.Instance().Insert(cacheKey, o, persistAppRestart);
}
public static void SetCache (string cacheKey, object o, CacheDependency dependency)
{
SetCache(cacheKey, o, dependency, false);
}
public static void SetCache (string cacheKey, object o, CacheDependency dependency, bool persistAppRestart)
{
CachingProvider.Instance().Insert(cacheKey, o, dependency, persistAppRestart);
}
public static void SetCache (string cacheKey, object o, CacheDependency dependency, DateTime absoluteExpiration,
TimeSpan slidingExpiration)
{
SetCache(cacheKey, o, dependency, absoluteExpiration, slidingExpiration, false);
}
public static void SetCache (string cacheKey, object o, CacheDependency dependency,
DateTime absoluteExpiration, TimeSpan slidingExpiration, bool persistAppRestart)
{
CachingProvider.Instance().Insert(cacheKey, o, dependency, absoluteExpiration, slidingExpiration, persistAppRestart);
}
public static void SetCache (string cacheKey, object o, TimeSpan slidingExpiration)
{
SetCache(cacheKey, o, slidingExpiration, false);
}
public static void SetCache (string cacheKey, object o, TimeSpan slidingExpiration, bool persistAppRestart)
{
CachingProvider.Instance().Insert(cacheKey, o, null, Cache.NoAbsoluteExpiration, slidingExpiration, persistAppRestart);
}
public static void SetCache (string cacheKey, object o, CacheDependency dependency, DateTime absoluteExpiration,
TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback)
{
SetCache(cacheKey, o, dependency, absoluteExpiration, slidingExpiration, priority, onRemoveCallback, false);
}
public static void SetCache (string cacheKey, object o, CacheDependency dependency, DateTime absoluteExpiration,
TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback, bool persistAppRestart)
{
CachingProvider.Instance().Insert(cacheKey, o, null, absoluteExpiration, slidingExpiration, persistAppRestart);
}
public static void SetCache (string cacheKey, object o, DateTime absoluteExpiration)
{
SetCache(cacheKey, o, absoluteExpiration, false);
}
public static void SetCache (string cacheKey, object o, DateTime absoluteExpiration, bool persistAppRestart)
{
CachingProvider.Instance().Insert(cacheKey, o, null, absoluteExpiration, Cache.NoSlidingExpiration, persistAppRestart);
}
public static void RemoveCache (string cacheKey)
{
CachingProvider.Instance().Remove(cacheKey);
}
public static void RemovePersistentCacheItem (string cacheKey)
{
CachingProvider.Instance().RemovePersistentCacheItem(cacheKey);
}
[Obsolete("This method is obsolete. Use the new specific methods: ClearHostCache, ClearPortalCache, ClearTabCache.")]
public static void ClearCoreCache (CoreCacheType type, int id, bool cascade)
{
switch (type)
{
case CoreCacheType.Host:
ClearHostCache(cascade);
break;
case CoreCacheType.Portal:
ClearPortalCache(id, cascade);
break;
case CoreCacheType.Tab:
TabInfo tabInfo;
TabController tabController = new TabController();
tabInfo = tabController.GetTab(id);
if (tabInfo != null)
ClearTabCache(id, tabInfo.PortalID);
break;
}
}
public static void ClearHostCache (bool cascade)
{
RemoveCache("GetHostSettings");
RemoveCache("GetPortalByAlias");
RemoveCache("CSS");
if (cascade)
{
PortalController portalController = new PortalController();
ArrayList arrPortals = portalController.GetPortals();
foreach (PortalInfo portalInfo in arrPortals)
{
ClearPortalCache(portalInfo.PortalID, cascade);
}
}
}
public static void ClearPortalCache (int portalId, bool cascade)
{
ArrayList arrTabs = GetCache("GetTabs" + portalId.ToString()) as ArrayList;
RemovePersistentCacheItem("GetPortalSettings" + portalId.ToString());
RemoveCache("GetTabs" + portalId.ToString());
if (cascade)
{
if (arrTabs == null)
{
TabController tabController = new TabController();
arrTabs = tabController.GetTabs(portalId);
}
foreach (TabInfo tabInfo in arrTabs)
{
ClearTabCache(tabInfo.TabID);
}
RemoveCache("GetTabPermissionsByPortal" + portalId.ToString());
}
}
public static void ClearTabCache(int tabId, int portalId)
{
ClearTabCache(tabId);
RemoveCache("GetTabPermissionsByPortal" + portalId.ToString());
}
private static void ClearTabCache (int tabId)
{
RemoveCache("GetTab" + tabId.ToString());
RemoveCache("GetPortalTabModules" + tabId.ToString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -