Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Caching' a large table in ASP.NET

I understand that each page refresh, especially in 'AjaxLand', causes my back-end/code-behind class to be called from scratch... This is a problem because my class (which is a member object in System.Web.UI.Page) contains A LOT of data that it sources from a database. So now every page refresh in AjaxLand is causing me to making large backend DB calls, rather than just to reuse a class object from memory. Any fix for this? Is this where session variables come into play? Are session variables the only option I have to retain an object in memory that is linked to a single-user and a single-session instance?

like image 687
TheNewGuy Avatar asked May 19 '10 15:05

TheNewGuy


2 Answers

You need ASP.Net Caching.

Specifically Data Caching.

like image 73
kervin Avatar answered Sep 28 '22 18:09

kervin


If your data is user-specific then Session would be the way to go. Be careful if you have a web farm or web garden. In which case you'll need a Session server or database for your session.

If your data is application-level then Application Data Cache could be the way to go. Be careful if you have limited RAM and your data is huge. The cache can empty itself at an inopportune moment.

Either way, you'll need to test how your application performs with your changes. You may even find going back to the database to be the least bad option.

In addition, you could have a look at Lazy Loading some of the data, to make it less heavy.

like image 34
Joe Ratzer Avatar answered Sep 28 '22 19:09

Joe Ratzer