c# - 找不到asp.net缓存键
问题描述
我正在运行 asp.net 应用程序。在一个函数中,我尝试添加一个缓存以供以后使用。但是,日志总是说找不到缓存键。似乎没有添加缓存键。首次加载页面时,提示“找不到”,这是正常的。然后我重新加载页面,它应该找到缓存键,但它仍然说找不到缓存键。我的代码有什么问题?这是我的代码
using System.Runtime.Caching;
public class ReportManager
{
protected static MemoryCache CACHE = new MemoryCache("Report_Cache");
public static DataSet KPISummaryReport(int companyID, int fromYear, int fromMonth, int toYear, int toMonth, string locationIDs, bool hideIfNoValue, string lang)
{
HttpResponseMessage result = null;
string requestUri = string.Format("Report/KPISummaryReport/?companyID={0}&fromYear={1}&fromMonth={2}&toYear={3}&toMonth={4}&locationIDs={5}&hideIfNoValue={6}&fmt=xml&lang={7}"
, companyID, fromYear, fromMonth, toYear, toMonth, locationIDs, hideIfNoValue, lang);
DataSet ds = null;
string cacheKey = "kpi_" + companyID + "_" + fromYear + "_" + fromMonth + "_" + toYear + "_" + toMonth + "_" + locationIDs;
ds = CACHE.Get(cacheKey) as DataSet;
if (ds != null)
{
Logger.Log(string.Format("Found the report dataset cache key {0}",cacheKey));
return ds;
}
else
{
Logger.Log(string.Format("Cannot find the report dataset cache key {0}",cacheKey));
ds = Util.GetData(_sustainabilityServiceURL, requestUri, out result);
var policy = new CacheItemPolicy { AbsoluteExpiration = DateTime.Now.AddMinutes(60d) };
CACHE.Add(cacheKey, ds, policy);
}
return ds;
}
}
解决方案
推荐阅读
- java - 在遍历分配的 LinkedList 时理解 OOP
- javascript - 当我的全局共享服务中的任何内容更新时,为什么我的组件对象不会自行更新?角
- javascript - 如何仅向文本添加边框并对齐中心
- python - 在字符串格式化 MySQL 期间并非所有参数都转换了
- r - 使用 R 将字符串转换为日期
- angular - Visual Studio Code 不会因 Angular 应用程序中未捕获的异常而停止
- node.js - 如何从 Async/Await 函数返回的 Promise 对象中提取对象(或数组)?
- node.js - 在NodeJs中制作最后没有id的url
- excel - 为excel中的产品总和创建论坛
- python - 从文件路径列表 Python 返回每个 ID 的最大文件列表