私はSystem.Web.Caching.Cache
自分のウェブサイトで使用されているアセンブリで使用しています。キーの有効期限(絶対有効期限)を10秒に設定しました(デバッグ用)。また、キーの削除時にコールバックを設定しました。
問題は、キャッシュが10秒ではなく20秒後に更新されていることです。
私はHttpRuntime.Cache
これに使用しています。
なぜそれが起こっているのかについての提案はありますか?
より多くの光を当てることができるコードサンプルを示したいと思います。
public void OnUpdate(string key
, CacheItemUpdateReason reason
, out object expensiveObject
, out CacheDependency dependency
, out DateTime absoluteExpiration
, out TimeSpan slidingExpiration)
{
using (StreamWriter sw = new StreamWriter(@"C:\temp\foo.txt",true))
{
sw.WriteLine("Updated Cache at " + DateTime.UtcNow);
}
expensiveObject = 11;
dependency = null;
absoluteExpiration = DateTime.UtcNow.AddSeconds(3);
slidingExpiration = Cache.NoSlidingExpiration;
}
protected void Page_Load(object sender, EventArgs e)
{
log.WriteInfo("Updated Cache", MethodBase.GetCurrentMethod());
Page.Cache.Insert("foo", (object)11, null, DateTime.UtcNow.AddSeconds(10), Cache.NoSlidingExpiration, new CacheItemUpdateCallback(OnUpdate));
}
ここでは、を使用しPage.Cache
ました。更新は3秒ごとに行う必要があります。以下のプリントアウトが示すように、実際には40秒ごとに実行されます。
Updated Cache at 1/28/2011 1:38:20 AM
Updated Cache at 1/28/2011 1:38:40 AM
Updated Cache at 1/28/2011 1:39:00 AM
Updated Cache at 1/28/2011 1:39:20 AM
Updated Cache at 1/28/2011 1:39:40 AM
Updated Cache at 1/28/2011 1:40:00 AM
Updated Cache at 1/28/2011 1:40:20 AM
Updated Cache at 1/28/2011 1:40:40 AM
Updated Cache at 1/28/2011 1:41:00 AM
Updated Cache at 1/28/2011 1:41:20 AM
Updated Cache at 1/28/2011 1:41:40 AM
Updated Cache at 1/28/2011 1:42:00 AM
Updated Cache at 1/28/2011 1:42:20 AM
Updated Cache at 1/28/2011 1:42:40 AM
何が問題なのか?