Read and write data from cache.
I have a table USER,I want stored data of USER table into cache memory of SQL SERVER and next time fetch data from cache in SQL SERVER for the performance purpose.Then how can i do?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.


Manish KumarRank #1,622 · 956 reputationPosted Nov 17, 2016, 1:35 AM EST
Brijesh RathorRank #7,391 · 242 reputationPosted Nov 17, 2016, 12:25 AM EST
public DataTable GetDataTableFromCacheOrDatabase() { DataTable dataTable = HttpContext.Current.Cache["secret key"] as DataTable; if(dataTable == null) { dataTable = GetDataTableFromDatabase(); HttpContext.Current.Cache["secret key"] = dataTable; } return dataTable; }You're going to need some mechanism to flush the data table from the cache if it changes. For example you could use an SqlCacheDependency.