In some cases due to trafic to the server it is needed to cache the data at client in order to save requests to the server.
In this scenario we will cache the data at client. The cached data then will be used again to select a item. If the data is not found in the cache then we made request to the server. The returned data is cached again and so on.

We will use the index.php from the Simple Autocomplete


The autocomplete.php code is:

<?php // include the Database driver class (we will use PDO). require_once 'jq-config.php'; require_once "php/jqGridPdo.php"; // include the jqUtils Class. The class is needed in all jqSuite components. require_once "php/jqUtils.php"; // include the jqAutocomplete Class require_once "php/jqAutocomplete.php"; // Connection to the server $conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD); // Tell the db that we use utf-8 $conn->query("SET NAMES utf8"); // create autocomplete instance $ac = new jqAutocomplete($conn); //write the select command $ac->SelectCommand = "SELECT CompanyName FROM customers WHERE CompanyName LIKE ? ORDER BY CompanyName"; // set the source from where to get data. In this case it is the same file. $ac->setSource("autocomplete.php"); // Set the cache option $ac->cache = true; // Enjoy $ac->renderAutocomplete("#company"); ?>