【发布时间】:2021-10-18 09:57:43
【问题描述】:
我创建了一个如下所示的基本缓存示例。当我发布到本地 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);
}
}
}
}
【问题讨论】:
标签: c# asp.net asp.net-mvc iis caching