I began my journey to speed up jQuery's autocomplete earlier this afternoon, and decided it was probably a good idea to begin memcaching everything. As suggested in this article: Speeding up autocomplete.
However, I am still dealing with slow response time even after installing and using Memcached.
The problem in my case is that I am dealing with extraordinarily long lists, in my case, over 6700 individual members. (All genera or genuses of all plants)
The bottleneck seems to be constructing the table and populating the client-side list, and it is not caused by retrieving the information from Memcached.
If anybody else has run into this particular problem, I would love to hear of a clever way to solve it. I will post my code below.
Note: This particular page is unavailable to the general public, and I am aware there are a few gaping security holes.
require_once 'oo/Database.php';
$mysqldb = new Database;
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect to memcache");
$sql = "SELECT DISTINCT `Genus` FROM importlist.plants";
$key = md5('query'.$sql);
$result = $memcache->get($key);
//check if we got something back
if($result == null) {
//fetch from database
$result = $mysqldb->rawSelect($sql)->getResult();
//set to memcache, expires after 1 hour
$memcache->set($key,$result,0,3600);
}
//Result array
$Genera = ($memcache->get($key));
//Add required "quotation marks" for autocomplete
foreach ($Genera as &$Genus){
$Genus = '"'.$Genus[Genus].'"';
}
$Genera = implode($Genera,',');
//PHP to generate jQuery
echo <<< EOT
<script>
$(function() {
var availableTags = [$Genera];
$( "#tags" ).autocomplete({
source: availableTags
});
});
</script>
EOT;
?>
<input id="tags" />