缓存的实现
public string GetCaChe()
{
//int result = DataSource.GetDataByDB(666);
List<MDMValue> result = new List<MDMValue>();
//key的名字一定要确保请求的准确性 DataSource GetDataByDB 666缺一不可
string key = "DataSource_GetDataByDB_666";
HttpRuntimeCache httpRuntimeCache = new HttpRuntimeCache();
//Func<List<MDMValue>> func=new Func<List<MDMValue>>(httpRuntimeCache.Add(key, result, 60000));
//httpRuntimeCache.GetOrCreate(key, func, 60000);
// if (CacheHelper.Exsits(key))
if (httpRuntimeCache.ContainsKey<List<MDMValue>>(key))
{
WriteLogs("调用缓存", "测试", "调用", "调用一个缓存");
//缓存存在,直接获取原数据
//result = CacheHelper.Get<List<MDMValue>>(key);
result = httpRuntimeCache.Get<List<MDMValue>>(key);
}
else
{
//缓存不存在,去生成缓存,并加入容器
result = CacheList();
//CacheHelper.Add(key, result);
httpRuntimeCache.Add(key, result, 300);
WriteLogs("新建缓存", "测试", "新建", "新建一个缓存");
}
return JsonConvert.SerializeObject(result);
}
有些东西需要改成自己的,仅供参考,直接粘贴行不通