2011-07-01 4 views
1

で期限切れ:私は、依存関係を設定摺動絶対期限できる場所メイクキャッシュオブジェクトIは、次のコードを持って深夜

var tempList = new BrandCollection(); 
      if (HttpContext.Current.Cache["cachedDeviceList"] == null) 
      { 
       tempList = Provider.GetDeviceData(info); 
       HttpContext.Current.Cache.Insert(...); 
      } 
      else 
      { 
       tempList = 
      } 

Cache.Insert()メソッドがオーバーロードされています。私は真夜中にキャッシュを期限切れにしたいと思っています。それ、どうやったら出来るの?少し早いですがお礼を!

答えて

2

これを実行する方法は絶対有効期限です。これは、「これは、今から20分後」ではなく、「これは絶対的な時点で期限切れになります」の省略形です。だから、アイテムをキャッシュに入れるときに、深夜がいつ計算され、それを満了ポイントとして使用する必要がありますか?

var tempList = new BrandCollection(); 
if (HttpContext.Current.Cache["cachedDeviceList"] == null) 
{ 
    tempList = Provider.GetDeviceData(info); 

    // Find out when midnight will be by taking Today and adding a day to it 
    DateTime expirationTime = DateTime.Today.AddDays(1) 
    HttpContext.Current.Cache.Insert("cachedDeviceList", tempList, null, expirationTime, NoSlidingExpiration, CacheItemPriority.Normal, null); 
} 
else 
{ 
    ... 
} 
関連する問題