[C#] 纯文本查看 复制代码 /// <summary>
/// 获取当前应用程序指定CacheKey的Cache值
/// </summary>
/// <param name="CacheKey"></param>
/// <returns></returns>
public static object GetCache(string CacheKey)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
return objCache[CacheKey];
}
/// <summary>
/// 设置当前应用程序指定CacheKey的Cache值
/// </summary>
/// <param name="CacheKey"></param>
/// <param name="objObject"></param>
public static void SetCache(string CacheKey, object objObject)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
objCache.Insert(CacheKey, objObject);
}
//传入程序集类型,使用系统激活器创建实例,并存入缓存
public static object CreateObject(string assemblyPath, string CacheKey)
{
object objType = GetCache(CacheKey);
if (objType == null)
{
try
{
objType = Assembly.Load(assemblyPath).CreateInstance(CacheKey);
SetCache(CacheKey, objType);// 写入缓存
}
catch (System.Exception err)
{
throw new Exception(err.Message);
}
}
return objType;
}
有需要的拿去。
|