📄 sitecache.cs
字号:
namespace PowerEasy.Components
{
using PowerEasy.Model.Accessories;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Caching;
public sealed class SiteCache
{
public const int DayFactor = 0x4380;
private static int factor = 5;
public const int HourFactor = 720;
private static readonly Cache m_Cache = InitSiteCache();
public const int MinuteFactor = 12;
public const double SecondFactor = 0.2;
private SiteCache()
{
}
public static IList<CacheInfo> AcquireCurrentCacheList(int cacheType)
{
string str;
switch (cacheType)
{
case 1:
str = @"CK_Content_NodeInfo_\S*";
break;
case 2:
str = @"CK_CommonModel_\S*";
break;
case 3:
str = @"CK_Label_\S*";
break;
case 4:
str = @"CK_Page_Category_\S*";
break;
default:
str = @"CK_\S*";
break;
}
Regex regex = new Regex(str, RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase);
IDictionaryEnumerator enumerator = m_Cache.GetEnumerator();
List<CacheInfo> list = new List<CacheInfo>();
while (enumerator.MoveNext())
{
if (regex.IsMatch(enumerator.Key.ToString()))
{
CacheInfo item = new CacheInfo();
item.CacheName = enumerator.Key.ToString();
string str2 = enumerator.Value.ToString();
if (str2.Length > 100)
{
str2 = str2.Substring(0, 100);
}
item.CacheValue = str2;
list.Add(item);
}
}
return list;
}
public static void Clear()
{
IDictionaryEnumerator enumerator = m_Cache.GetEnumerator();
ArrayList list = new ArrayList();
while (enumerator.MoveNext())
{
list.Add(enumerator.Key);
}
foreach (string str in list)
{
m_Cache.Remove(str);
}
}
public static object Get(string key)
{
return m_Cache[key];
}
private static Cache InitSiteCache()
{
HttpContext current = HttpContext.Current;
if (current != null)
{
return current.Cache;
}
return HttpRuntime.Cache;
}
public static void Insert(string key, object obj)
{
Insert(key, obj, null, 1);
}
public static void Insert(string key, object obj, int seconds)
{
Insert(key, obj, null, seconds);
}
public static void Insert(string key, object obj, CacheDependency dep)
{
Insert(key, obj, dep, 0x21c0);
}
public static void Insert(string key, object obj, int seconds, CacheItemPriority priority)
{
Insert(key, obj, null, seconds, priority);
}
public static void Insert(string key, object obj, CacheDependency dep, int seconds)
{
Insert(key, obj, dep, seconds, CacheItemPriority.NotRemovable);
}
public static void Insert(string key, object obj, CacheDependency dep, int seconds, CacheItemPriority priority)
{
if (obj != null)
{
m_Cache.Insert(key, obj, dep, DateTime.Now.AddSeconds((double) (Factor * seconds)), TimeSpan.Zero, priority, null);
}
}
public static void Max(string key, object obj)
{
Max(key, obj, null);
}
public static void Max(string key, object obj, CacheDependency dep)
{
if (obj != null)
{
m_Cache.Insert(key, obj, dep, DateTime.MaxValue, TimeSpan.Zero, CacheItemPriority.Normal, null);
}
}
public static void MicroInsert(string key, object obj, int secondFactor)
{
if (obj != null)
{
m_Cache.Insert(key, obj, null, DateTime.Now.AddSeconds((double) (Factor * secondFactor)), TimeSpan.Zero);
}
}
public static void Remove(string key)
{
m_Cache.Remove(key);
}
public static void RemoveByPattern(string pattern)
{
IDictionaryEnumerator enumerator = m_Cache.GetEnumerator();
Regex regex = new Regex(pattern, RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase);
ArrayList list = new ArrayList();
while (enumerator.MoveNext())
{
if (regex.IsMatch(enumerator.Key.ToString()))
{
list.Add(enumerator.Key);
}
}
foreach (string str in list)
{
m_Cache.Remove(str);
}
}
public static IList<CacheInfo> CurrentCacheList
{
get
{
IDictionaryEnumerator enumerator = m_Cache.GetEnumerator();
IList<CacheInfo> list = new List<CacheInfo>();
while (enumerator.MoveNext())
{
CacheInfo item = new CacheInfo();
item.CacheName = enumerator.Key.ToString();
string str = enumerator.Value.ToString();
if (str.Length > 100)
{
str = str.Substring(0, 100);
}
item.CacheValue = str;
list.Add(item);
}
return list;
}
}
public static int Factor
{
get
{
return factor;
}
set
{
factor = value;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -