|
Too many capital letters, but I digress. I want to share a tip with you. And I'm so happy .NET 2.0 added the WriteXml family of methods to a DataTable, instead of just a DataSet. It's true you didn't really terribly need it because you could add the table to a set and then serialize that, but why make the server do extra work?
If you're like me you have a database in your site, and it does different things. I even have a small desktop app I use to set things in the database, that can reflect in my pages. Hopefully I haven't lost you. Because the next thing we probably have in common is that we use queries that have to be dynamic, the answer could be changing all the time, but we also use some queries that are more static, the answer might not change for months at a time. Last requirement is that we know them apart.
So use xml! Say have restricted membership, have to invite and then accept new users. There are a few pages where you need the list of members, probably to fill a drop down, or maybe to put names with ID numbers. Don't put this in a session variable because that wastes so much, and it's also good to not put it in an application variable. That one doesn't hurt nearly as bad because there's only one copy in memory, and it doesn't force session management if you aren't using it already. But it's still not perfect. Once you fill your datatable, and then do whatever you need with it, write the file out to xml. Then next time you need the data, read it back from the xml instead. At some point in time you delete the xml file to invalidate this cache.
It will take your ASPx as much time to get the data from xml as it will from a database query, because parsing text is no joke. But when it does this, it doesn't put any pressure on the database. It's not just locks we're saving, it's a whole bunch less queries running at the same time trading access to the computer's resources. And that makes your site more scalable, even if it doesn't make it faster.
|