title: jQuery UI autocomplete caching using $.map function
body: <p>I am trying to implement caching using jQuery UI autocomplete.
  I am using jQuery 1.4.4 and UI 1.8.6</p>
  
  <p>Here is the basic code that I got working:</p>
  
  <pre><code>$('#searchbox').autocomplete({
      source: function(request, response) {
              if (xhr === lastXhr) {
                  response( $.map(data, function(item) {
                      return {
                          label: item.NAME + (item.PRFNM ? ' (' + item.PRFNM + ')' : '') + ', ' + item.JOBTITLE,
                          value: item.NAME
                      };
                  }));
              } 
          });
      }
  });
  </code></pre>
  
  <p>Here is my attempt to get caching to work from looking at the example:</p>
  
  <pre><code>var cache = {},
      lastXhr;
  $('#searchbox').autocomplete({
      source: function(request, response) {
          var term = request.term;
          if (term in cache) {
              response($.map(cache[term], function(item) {
                  return {
                      label: item.NAME + (item.PRFNM ? ' (' + item.PRFNM + ')' : '') + ', ' + item.JOBTITLE,
                      value: item.NAME
                  };
              }));
          }
          lastXhr = $.getJSON( "getdata.php", request, function(data, status, xhr) {
              cache[term] = $.map(data, function(item) {
                  return {
                      label: item.NAME + (item.PRFNM ? ' (' + item.PRFNM + ')' : '') + ', ' + item.JOBTITLE,
                      value: item.NAME
                  };
              }); 
              if (xhr === lastXhr) {
                  response( $.map(data, function(item) {
                      return {
                          label: item.NAME + (item.PRFNM ? ' (' + item.PRFNM + ')' : '') + ', ' + item.JOBTITLE,
                          value: item.NAME
                      };
                  }));
              } 
          });
      }
  });
  </code></pre>
  
  <p>Any takers out there?</p>