private void getInfoClass( int t)
{
string CacheKey = "cacheclass" + t.ToString();
object objModle = Jake.DataCache.GetCache(CacheKey);//从缓存中获取
DataTable dt=null;
if (objModle == null)//如果缓存中没有则读取数据库
{
Jake.BLL.NewsManage.NewsClass nc = new Jake.BLL.NewsManage.NewsClass();
dt = nc.GetList("").Tables[0];
objModle = dt;
if (objModle != null)
{
System.Web.Caching.SqlCacheDependency dep = new System.Web.Caching.SqlCacheDependency("YD_JWC_JAKE", "T_NewsClass");
Jake.DataCache.SetCache(CacheKey, objModle, dep);
}
}
else
{
dt = (DataTable)objModle; //缓存中有就直接读取缓存,不需要访问数据库
}
DataRow[] drs = dt.Select("","classid");
StringBuilder sb =new StringBuilder();
sb.Append("
");
foreach (DataRow r in drs)
{
string cid=r["ClassId"].ToString();
Security js = new Security();
string decrystr = Jake.Common.ConfigHelper.GetConfigString("DecryStr");//获得加密密钥
cid = js.EncryptQueryString(cid, decrystr);
string cdesc=r["ClassDesc"].ToString();
if (t == 1)
{
sb.Append("- " + cdesc + "
");
}
else if (t == 2)
{
sb.Append("- " + cdesc + "
");
}
else
sb.Append("- " + cdesc + "
");
}
sb.Append("
");
Response.Write(sb);
}
using System;
using System.Collections.Generic;
using System.Web;
using System.Text;
namespace Jake
{
public class DataCache
{
///
/// 获取当前应用程序指定CacheKey的Cache值
/// ///
///
public static object GetCache(string CacheKey)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
return objCache[CacheKey];
}
///
/// 设置当前应用程序指定CacheKey的Cache值
/// ///
///
public static void SetCache(string CacheKey, object objObject)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
objCache.Insert(CacheKey, objObject);
}
///
/// 设置已缓存依赖的方式缓存数据
/// ///
键值
///
缓存对象
///
缓存依赖项
public static void SetCache(string CacheKey, object objObject, System.Web.Caching.CacheDependency dep)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
objCache.Insert(
CacheKey,
objObject,
dep,
System.Web.Caching.Cache.NoAbsoluteExpiration,//从不过期
System.Web.Caching.Cache.NoSlidingExpiration,//禁用可调过期
System.Web.Caching.CacheItemPriority.Default,
null
);
}
}
}