简单缓存 datatable
DataTable dt = new DataTable();
if (Cache["mytablecache"] == null)
{
using (SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=LocalDB;Integrated Security=True"))
{
con.Open();
SqlDataAdapter adapter = new SqlDataAdapter("SELECT top 100 * FROM [Money_CostDetail]", con);
adapter.Fill(dt);
}
Cache.Insert("mytablecache", dt, null, DateTime.UtcNow.AddMinutes(1), TimeSpan.Zero);
}
else
{
dt = Cache["mytablecache"] as DataTable;
}
if (Cache["mytablecache"] == null)
{
using (SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=LocalDB;Integrated Security=True"))
{
con.Open();
SqlDataAdapter adapter = new SqlDataAdapter("SELECT top 100 * FROM [Money_CostDetail]", con);
adapter.Fill(dt);
}
Cache.Insert("mytablecache", dt, null, DateTime.UtcNow.AddMinutes(1), TimeSpan.Zero);
}
else
{
dt = Cache["mytablecache"] as DataTable;
}
走向地狱的途中,不小心走了程序员这条路,路上一个个黑心的老板,和暗无天日的加班,我才发现,通往地狱的路径中,我们这行是最短的。