c# - Asp.net 缓存在 IIS 上不起作用。IIS上有没有设置
问题描述
我创建了一个如下所示的基本缓存示例。当我发布到本地 IIS 时,我的代码运行良好。但是,当我发布我的真实服务器时无法正常工作。没有任何错误。但是缓存总是空的。这可能是什么原因?IIS 或其他 Windows 配置中是否有任何设置?
using System;
using System.Runtime.Caching;
using System.Web.Http;
namespace ToplumMerkezleriCommonApi.Controllers
{
public class ValuesController : ApiController
{
protected ObjectCache Cache => MemoryCache.Default;
protected CacheItemPolicy policy = null;
public object Get(string id)
{
if (Cache.Get("testcache") == null)
{
GetAllCacheItems();
}
return Cache[id] as Object;
}
private void GetAllCacheItems()
{
using (CommunityCenterEntities context = new CommunityCenterEntities())
{
policy = new CacheItemPolicy();
policy.AbsoluteExpiration = DateTimeOffset.Now.AddHours(24);
Cache.Set("testcache", DateTime.Now.ToString(), policy);
}
}
}
}
解决方案
请检查,转到 IIS 管理器-> 站点节点-> 输出缓存-> 编辑功能设置-> 取消选中启用缓存对于静态文件,您启用 IIS 管理器-> 站点节点-> HTTP 响应标头-> 设置常用标头->使网页内容过期->立即。
推荐阅读
- javascript - React + Django 中的 URL 路由问题
- qt - 从 C++ 类调用 QML 函数?
- python - 在不平衡数据集上解释 AUC、准确性和 f1 分数
- django - 形式和模型之间的循环依赖
- php - MySQL没有将转义字符转换为原始字符串
- kotlin - 持久性.CordaPersistence。- 清理任务失败:[errorCode=1d5efik, moreInformationAt=https://errors.corda.net/OS/4.4/1d5efik]
- r - r中的随机效应模型
- python - 为什么我没有得到相同的结果?这两个代码不是表示相同的东西吗?
- r - R中的逻辑回归以获得SNP列表以获得汇总统计信息
- azure - Azure 功能 - 有机会通过 apt-get 安装软件包吗?