CacheItemRemovedReason reason;
bool itemRemoved = false;
public CacheItemRemovedCallback onRemove = null;
public void M_Cache(string Key, DataTable Dt)
{
itemRemoved = false;
onRemove = new CacheItemRemovedCallback(this.RemovedCallback);
if (HttpRuntime.Cache[Key] == null)
{
HttpRuntime.Cache.Insert(Key, Dt, null, DateTime.Now.AddSeconds(Untity.Time), TimeSpan.Zero, CacheItemPriority.Default, onRemove);//Untity.Time=60
}
else
{
DataTable NewDt = (DataTable)HttpRuntime.Cache.Get(Key);
object[] obj = new object[NewDt.Columns.Count];
for (int i = 0; i < Dt.Rows.Count; i++)
{
Dt.Rows[i].ItemArray.CopyTo(obj, 0);
NewDt.Rows.Add(obj);
}
HttpRuntime.Cache.Remove(Key);
HttpRuntime.Cache.Insert(Key, NewDt, null, DateTime.Now.AddSeconds(Untity.Time), TimeSpan.Zero, CacheItemPriority.Default, onRemove);
}
}
HttpRuntime.Cache.Remove(Key);
我把这个删了也不行
HttpRuntime.Cache.Remove(Key);删了之后把下一行的的HttpRuntime.Cache.Insert的改成Add就行了!
还是谢谢你
当要加入的缓存项已经在Cache中存在时,Insert将会覆盖原有的缓存项目,而Add则不会修改原有缓存项。
我把这个给忘了。哎~~~
解决就好。remove也是有关系的。