【发布时间】:2011-10-16 11:00:07
【问题描述】:
我正在创建我的缓存服务并使用Memorycache 来缓存我的数据。缓存数据配置为在 12 小时后过期。一小时后,我的缓存数据不复存在。 IIS (7.0) 工作池配置为在 1740 分钟后过期。我正在缓存大约 200 M 的数据,每个缓存项小于 100 字节。
以前有人遇到过这个问题,或者我可能在这里做错了吗?
这是我用来实例化 MemoryCache 的代码。
private const string ConstCacheMemoryLimitMegabytes = "cacheMemoryLimitMegabytes";
private const string ConstCacheMemoryLimitMegabytesValue = "2000";
private const int CacheDefaultTimeOut = 720;
// Percentage of server memory to use
private const string ConstPhysicalMemoryLimitPercentage = "physicalMemoryLimitPercentage";
private const string ConstPhysicalMemoryLimitPercentageValue = "100";
// The maximum time that can occur before memory statistics are updated.
private const string ConstPollingInterval = "pollingInterval";
private const string ConstPollingIntervalValue = "02:00:00";
var config = new NameValueCollection
{
{ ConstCacheMemoryLimitMegabytes, ConstCacheMemoryLimitMegabytesValue },
{ ConstPhysicalMemoryLimitPercentage, ConstPhysicalMemoryLimitPercentageValue },
{ ConstPollingInterval, ConstPollingIntervalValue}
};
var _cachePolicy = new CacheItemPolicy
{
AbsoluteExpiration = ConvertIntToMinDateTimeOffSet(CacheDefaultTimeOut) // Setting this to expire 12 hours later.
};
_memoryCache = new MemoryCache("MyCustomCache", config);
var cacheItem = new CacheItem(key, item);
_memoryCache.Add(cacheItem, _cachePolicy);
private static DateTimeOffset ConvertIntToMinDateTimeOffSet(int cacheExpiryIntervalInMinute)
{
return new DateTimeOffset(DateTime.Now.AddMinutes(cacheExpiryIntervalInMinute));
}
时区为 UTC + 8:00(吉隆坡、新加坡)
【问题讨论】:
-
记录您居住的时区。