jQuery Autocomplete - Is caching no longer an option?
Asked Answered
C

1

7

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

Correspond answered 10/1, 2012 at 23:4 Comment(0)
R
9

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.

Rectangle answered 10/1, 2012 at 23:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.