基本上我将某个数据集存储在 asp.net 缓存中。我想知道的是,这样做是否会保持 mysql 连接打开?即使我使用的是“使用”语句?
String cacheName="MY_QUERY_QACHE";
IEnumerable<DataRow> datarows = (IEnumerable<DataRow>)HttpRuntime.Cache[cacheName];
if(datarows==null){
using (MySqlConnection conn = new MySqlConnection("MY CONNECTION STRING")){
conn.Open();
String strSQL="SELECT * FROM my_table etc... etc....";
MySqlCommand cmd = new MySqlCommand(strSQL, conn);
MySqlDataAdapter da = new MySqlDataAdapter();
DataSet ds = new DataSet();
cmd.Prepare();
da.SelectCommand = cmd;
da.Fill(ds);
datarows = ds.Tables[0].AsEnumerable();
conn.Close();
}
HttpRuntime.Cache.Add(cacheName,
datarows,
null,
DateTime.Now.AddDays(1),
System.Web.Caching.Cache.NoSlidingExpiration,
System.Web.Caching.CacheItemPriority.Normal,
null
);
}