title: jQuery Autocomplete: How to enable cache?
body: <p>This is my source code that use a function to push the suggestion array:</p>
  
  <pre><code>jQuery(document).ready(function ($){
      var cache = {};
      function split( val ) {
          return val.split( /,\s*/ );
      }
  
      function extractLast( term ) {
          return split( term ).pop();
      }
  
      $("#ctags-input")
          .bind( "keydown", function( event ) {
              if ( event.keyCode === $.ui.keyCode.TAB &amp;&amp;
                      $( this ).data( "autocomplete" ).menu.active ) {
                  event.preventDefault();
              }
          })
  
      .autocomplete({ 
  
          source: function(req, add){
              var ctags_action = 'suggest_tags';
  
              var term = req.term;
              if (term in cache) {
                 add(cache[term]);
                 return;
              }
  
      $.getJSON(SuggestTags.url+'?callback=?&amp;action='+ctags_action, req, function(data) {
                  var suggestions = [];
                  $.each(data, function(i, val){                              
                      suggestions.push({
                          label: val.name,
                          count: val.count
                      });
                  });
                  cache[term] = suggestions;  
                  add(suggestions);
  
              });
          },          
          focus: function() {
              return false;
          },
  
          select: function( event, ui ) {
              var terms = split( this.value );
              terms.pop();
              terms.push( ui.item.value );
              terms.push( "" );
              this.value = terms.join( ", " );
              return false;
          }   
      })
  
      .data( "autocomplete" )._renderItem = function( ul, item ) {        
          return $("&lt;li&gt;&lt;/li&gt;")
          .data("item.autocomplete", item)
          .append("&lt;a&gt;" + item.label + " (" + item.count+ ")&lt;/a&gt;")        
          .appendTo(ul);
      };      
  });
  </code></pre>
  
  <p>To add cache ability, jQ UI site demo directly uses response for data:</p>
  
  <pre><code>source: function( request, response ) {
     var term = request.term;
      if ( term in cache ) {
        response( cache[ term ] );
        return;
      }
  
     lastXhr = $.getJSON( "search.php", request, function( data, status, xhr ) {
      cache[ term ] = data;
      if ( xhr === lastXhr ) {
          response( data );
      }
   });
  }
  </code></pre>
  
  <p>How to implement this cache demo in my code? </p>