2011-10-26 56 views
2

我使用緩存來存儲數據,但在一些操作,比如添加/更新用我想要重新加載我使用下面的方法,但它沒有工作,有沒有其他的解決辦法如何過期緩存

Response.Cache.SetSlidingExpiration(true); 

還試圖

cache["MoiveLIst"] = null; 

,但沒有結果

上面的代碼應該做,如果條件爲真,但它沒有,如果塊不執行,因爲高速緩存不爲空,我怎麼可以MAK E - 這空

if(Cache ["MovieList"]==null)     
{ 
    Cache.Insert("MovieList", _client.GetAllMovies(), null, timespane, System.Web.Caching.Cache.NoSlidingExpiration); 
} 
List<Movie> oData = Cache["MovieList"] as List<Movie>; 
+0

使用前Cache.Remove Method什麼迫使緩存過期在ASP.NET?](http://stackoverflow.com/questions/的最佳方法533867 /最新最最佳方法換迫使緩存期滿-在-ASP-淨) – Damith

回答

0

你可以插入

if(Cache["MoiveLIst"] != null) 
    Cache.Remove("MoiveLIst"); 

Cache.Insert("MovieList", _client.GetAllMovies(), null, timespane, System.Web.Caching.Cache.NoSlidingExpiration); 
List<Movie> oData = Cache["MovieList"] as List<Movie>; 
相關[