Reputation: 63
We would like to cache data for some dropdown lists on the client machine to reduce the transfer of slow changing info. This data will be used on multiple pages within a business app so for example a customer list of 5,000 customers is frequently used either for searching, creating a sales order, or other purposes. We've tried both full load of the data with the page as well as paged database access and loading the grid on demand which brings back only 25-50 records. Users are complaining about the performance of both options and want it faster so we are looking for options on how to cache the data at the client for reuse.
We've seen some notation that online regarding caching that perhaps a JS file could be generated by the server and cached locally to be the datasource for the ddl but never found how to do this.
Any suggestions? Or other options that you would recommend?
Note: we'll need to address expiry of this too as some of the lists will change a few times per day and should be refreshed (not on a timer but when they change based on response codes).
Upvotes: 3
Views: 2180
Reputation: 116987
Before you attempt to start caching things on the client, which is an unpredictable way of doing things for the simple reason that you have no control over how their browser is set up to cache (what if they have cache set to "never"?), there are a lot of things you should look at.
Have you looked at caching on the server first? You can use the OutputCache and vary it by parameter (the grid page number, for example) for partial caching of all the viewed datasets.
What exactly is slow about the user experience? Analyze it with firebug or fiddler and see how many requests are being made to the server per page. Simply minimizing the number of HTTP requests being sent (by merging and minifying CSS and javascripts for example) will do wonders for the response time.
What's in your ViewState? Reduce the amount of data being sent back and forth in ViewState for faster page loading.
Is the data fetching routine on the server taking too long? Optimize it, and perhaps cache the data on the server so you don't have to go out to the database as often.
Maybe you've tried all this already, but I thought I'd throw it out there because relying on client-side caching can be a frustrating excercise.
Upvotes: 3
Reputation: 630559
You could do this via javascript, convert the list to JSON and serve it up via a script tag from server cache. I say JSON because something like jQuery or any other javascript framework can make easy use of it.
e.g. in the html/aspx:
<script src="CustomerList.aspx?Refresh=12308798798023745" type="text/javascript"></script>
The Refresh being the DateTime.Now.Ticks of the last time it changed on the server. So while you're putting this tag in every page, the client would fetch it only once, and again when it actually changed on the server.
Something like this server-side:
public class Cache {
public static List<Customer> Customers { get; set; }
public static DateTime LastRefresh { get; set; }
public static void RefreshCustomers {
//Populate Customers, Customers = blah;
LastRefresh = DateTime.Now;
}
}
In the page:
ScriptTagwithRunAtServer.Src = "CustomerList.aspx?Refresh=" + Cache.LastRefresh.Ticks;
Any way you render that tag would be fine, just an example. The CustomerList.aspx
page would just render the Cache.Customers into json form...and your page would run a little javascript to make whatever use of it.
Just an idea, please comment if it interests you and I'm leaving something out.
Upvotes: 2