Devlico.Us
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @devlicious

Alan Northam



Practical Implementation - spending some cache.

Take a look at my previous post for the details on a cache helper method that I like to use.  In this post, we'll be putting it to work (the word for today is J - O - B).  Here's a look at the code for reference.


Enter the ASP.NET AJAX AutoComplete Extender.  It's a perfect candidate for a little cache help.  I certainly wouldn't want the database being hit every time a user typed the next letter in the autocomplete box.  I apologize for wearing you down with all this talk.  I think I've said too much.  Let's look at the code for autocomplete webservice.


The webservice takes the first part of the prefixText (minimumPrefixLength should match the value in the autocomplete extender control) and queries the database for all matches.  It stores that result set in cache and then filters the list by prefixText if needed.  Finally it will take the top X (count is specified by the control) and return it to the control.

If a user was searching for "automobile", after typing a-u-t all possible results would be cache so that each successive letter will not hit the database.  Another database hit will be incurred when a user searches for a different 3 letter prefix. 

I'm attaching the full sample code along with a Sql Express database that contains some huge word list I found online (to be attached later, technical difficulties).  Enjoy and try not to spend it all in one place.
 



Comments

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# March 24, 2008 9:02 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!

Our Sponsors

Red-Gate!