我有一個高速緩存方法如下: -更改緩存改變列表對象C#
編輯
// Cache Methods
public void dbcTvShowsList(ref List<TvShow> listTvShows, ref Int16 err)
{
// Check to see if tv shows are already in cache
if (HttpRuntime.Cache["TvShows"] != null)
{
listTvShows = (List<TvShow>)HttpRuntime.Cache["TvShows"];
// Make sure we have data in the list
if (listTvShows.Count == 0)
{
// No data in the list. Read it from the database
// Now cache the data
}
else
{
// Now cache the data
HttpRuntime.Cache.Insert("TvShows", listTvShows, null, DateTime.Now.AddMinutes(3), System.Web.Caching.Cache.NoSlidingExpiration);
}
}
else
{
// Data no longer in cache. Read it from the database
// If we got data, cache it
if (err == 0)
{
HttpRuntime.Cache.Insert("TvShows", listTvShows, null, DateTime.Now.AddMinutes(3), System.Web.Caching.Cache.NoSlidingExpiration);
}
}
}
現在在我的班級我讀緩存的數據,然後出不來了一些更改, 。但是這影響了我的緩存數據,如下所示: -
new iNGRID_Data.TvShows.DataMethods().dbcTvShowsList(ref _TvShows, ref err);
TvShow TvShowAll = new TvShow();
TvShowAll.ShowId = 0;
TvShowAll.ShowName = "All Programming";
_TvShows.Add(TvShowAll);
這會修改全局緩存並將所有編程添加到它。
你能告訴我爲什麼會發生這種情況嗎?
問候 阿布舍克
您只有對列表的引用。這不是一個副本。 – scheien