Cache my Grid view when I do paging and sorting, but hit the database for a page load and a search action
Posted on 2009-07-16
I have a very simple GridView working with Objectdatasource that is calling a Bussiness method that return a DataTable object. in my case I did a top 2000 records. using the built paging and sorting from the Grid View I hit the query each time I do any of the two operations.
I found out that the ObjectDatasource has a Cache property which works but because my page is search page. I want to store the results for each user in a Cache dependency key (this way each user who searches will have his own Cache, using the Session ID key).
Here are the rules I want the Cache to respect:
Page Load always hit the database.
Paging hit the cache if available
Sorting hit the cache if available
Clicking on the search button to get a new set of results hit the database.
Can this be done? Did anyone did something like that ?
I could not find one sample online for something so basic and simple.
Personally I could not get this work, I had problems clearing the Cache.
A code sample would be great.
Thanks in advance.