Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Autocomplete - Is caching no longer an option?

Using jQuery Autocomplete, according to the docs you have to do the following to cache:

<script>
$(function() {
    var cache = {},
        lastXhr;
    $( "#birds" ).autocomplete({
        minLength: 2,
        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 );
                }
            });
        }
    });
});
</script>

Didn't there used to be an option to cache? Thanks

like image 246
AnApprentice Avatar asked Jan 10 '12 23:01

AnApprentice


1 Answers

Caching for jQueryUI autocomplete was never an option.

There was a cacheLength option for jQuery autocomplete (Jörn Zaefferer's now deprecated autocomplete plugin).

In the migration guide from autocomplete --> jQueryUI autocomplete, Jörn mentions this:

cacheLength: There is no built-in caching support anymore, but it's really easy to implement your own, as shown by the Remote with caching demo.

If you are using the caching implementation frequently, you could wrap the functionality in another plugin that encapsulates it.

like image 115
Andrew Whitaker Avatar answered Oct 31 '22 15:10

Andrew Whitaker