我想使用System.Runtime.Caching.MemoryCache來緩存我的一些對象。我想確保對象每天刷新一次(絕對到期),但如果它在最近一小時內沒有被使用(滑動到期),我也想使其到期。 我嘗試做:組合滑動和絕對過期
object item = "someitem";
var cache = MemoryCache.Default;
var policy = new CacheItemPolicy();
policy.AbsoluteExpiration = DateTime.Now.AddDays(1);
policy.SlidingExpiration = TimeSpan.FromHours(1);
cache.Add("somekey", item, policy);
但我發現了一個「ArgumentException的」與「AbsoluteExpiration必須DateTimeOffset.MaxValue或SlidingExpiration必須TimeSpan.Zero。」
我認爲這是一個很好的解決方法,如果它工作。謝謝 – Andres 2013-05-16 20:44:35