Connect with Expertise | Find Experts, Get Answers, Share Insights

Caching frequently changing data in ASP.NET web applications

Frinavale's Avatar
E
M
C
 
Join Date: Oct 2006
Location: The Great White North
Posts: 7,106
#1: Feb 8 '10
I am maintaining a intranet web application that allows users to Search/Add/Edit items and run reports.

When the user searches for items or runs a report, the items/report-records were stored into Session so that I didn't have to recreate the data source for functions like paging, sorting, editing etc.

Whenever a user would open a new tab, I'd check to see if there were search results or a report in Session and if so I would warn the user about the possibility of messing things up in the other tab.

A new requirement has been added to the application that states that users should be allowed to work in multiple tabs.

I've modified the application so that it no longer stores the the search results and reports in Session. Instead it caches the search criteria used to generate the search results/report in ViewState and uses that to recreate the datasource each postback.

I found that when the user's search resulted in 4000+ items it took 13 seconds to run the search. That means that after the user has done the search...and if they caused a postback they'd have to wait another 13 seconds (this was particularity bad when the user does something small like sorting/paging etc).

I wasn't happy with this in the slightest but eventually I was told to leave it as it is because the user is expected to refine their search results to just a few items...in which case it took less than second to return.

I'm working on the reports right now.
Reports can be Very large (well over 4000 records) and I can see this lag-time being a problem.

I could continue to use Session to "cache" the search results and the reports...and create unique IDs for each tab.

The thing is that I'm worried about Session growing too large as multiple users may be connecting with multiple tabs, running search and reports in each tab. Session could potentially grow too large and cause the application to be recycled.

I'm considering using ASP.NET's "Cache" but from what I've been reading it's not really meant to be used with data that is frequently changing like this...it's really meant to be used in situations where the data remains constant for long periods of time and doesn't really change much.

I am looking for any input on this how I should cache these results (I'm even thinking of using an XML file server side...since I don't have access to a database)

Thanks a lot

-Frinny

tlhintoq's Avatar
E
C
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 3,476
#2: Feb 8 '10

re: Caching frequently changing data in ASP.NET web applications


I don't know if it helps, but the September 2009 issue of MSDN magazine did an article on distributed cacheing. (Page 9)
http://msdn.microsoft.com/ru-ru/maga...50(en-us).aspx
Frinavale's Avatar
E
M
C
 
Join Date: Oct 2006
Location: The Great White North
Posts: 7,106
#3: Feb 8 '10

re: Caching frequently changing data in ASP.NET web applications


Do you happen to know if Cache in ASP.NET works like Session: if it grows too large it recycles the worker process?

I've been aware of ASP.NET Cache for a long time now but I've never used it and am not intimate with the concept whatsoever.

If it doesn't recycle, then I might cache the search results/reports for every page using the search criteria as the key.... refreshing the data every time the user "preforms the search" or "generates a report" by clicking the link/button responsible for doing the task.

The thing is that the reports/search results may be quite large...and there are millions of combination to create these search-results/reports (actually maybe billions because of that one check box list that has over 80 options in it)

-Frinny
Frinavale's Avatar
E
M
C
 
Join Date: Oct 2006
Location: The Great White North
Posts: 7,106
#4: Feb 8 '10

re: Caching frequently changing data in ASP.NET web applications


The article is a very interesting read.

My application is not designed to run in a web-farm/garden configuration though...it simply wouldn't work (Session is InProc and the whole application would have to be changed to support a different Session...considering that I don't have access to a database this would be pretty difficult)

So the article doesn't really help me out much.

Thanks though!
-Frinny
tlhintoq's Avatar
E
C
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 3,476
#5: Feb 8 '10

re: Caching frequently changing data in ASP.NET web applications


Do you happen to know if Cache in ASP.NET works like Session: if it grows too large it recycles the worker process?
You lost me after 'Do you happen to know'

I have never done anything in ASP. I just happened to be reading that issue when your post came in so it clicked.
Frinavale's Avatar
E
M
C
 
Join Date: Oct 2006
Location: The Great White North
Posts: 7,106
#6: Feb 8 '10

re: Caching frequently changing data in ASP.NET web applications


I've decided to just jump in and try using Cache (with a sliding expiration of something like 5 minutes) :)

-Frinny
Reply