Bypass all caching on jQuery.autocomplete (1.02)

I am using jQuery.autocomplete (1.02) in my search box and I want an exact match of string and substring. I don’t care (yet!) About loading the database, I am glad that it launches a request for each keystroke and completely bypasses the caching - I just do not want something to be missed.

To this end, I tried to set cacheLength = 1, the minimum allowed, but the autocomplete function refuses to reset the GET request for each key up.

searchbox GET_request 'a' -> http://localhost/service_search_request?q=a 'ar' -> http://localhost/service_search_request?q=ar 'ars' -> http://localhost/service_search_request?q=ars 

Instead, it sends the first and third and skips the second, giving me the wrong results for 'ar': - / I cleared my cache and sessions, but it looks like some kind of caching is going on. AFAIK I do not have a proxy, and I update every time. It appears that this behavior comes from jQuery.autocomplete.

So my questions are ...

A) Is it possible? that is, is it a function or maybe an error?

B) If so, is there a clean way? ...

C) If not, which auto-complete would you use instead?

Naturally, D) No, you are just misusing it in the spirit! there is always an opportunity, and indeed one that I would rather spend the time going along this path - provided that it comes with a link to documents that I could not find / read!

Greetings

Roger:)

+4
source share
5 answers

I wonder why cacheLength does not work, but also has problems with autocomplete. IMHO, there are errors in it. However, in the options list , there is matchSubset , you can set the value to false.

EDIT: somewhere around line 335, the query function is called. You can add some debugging messages to it to find out what is going on: (note: you need firebug or "console" will be unknown)

 function request(term, success, failure) { console.debug("ac request..."); if (!options.matchCase) term = term.toLowerCase(); var data = cache.load(term); console.debug("ac request 1, loaded data from cache: " + data + " term: " + term); // recieve the cached data if (data && data.length) { success(term, data); // if an AJAX url has been supplied, try loading the data now } else if( (typeof options.url == "string") && (options.url.length > 0) ){ console.debug("ac request 2, data is not in the cache, request it"); 

"flushCache" can be easily used in a function that you can attach / set as parameters. I used this to clear the cache if there can be more data in the backend:

 formatItem: function (data,i,n,value){ if(i === (this.max -1)){ console.debug("flushCache"); jQuery(this).flushCache(); } return data[1] + " (" + data[0] + ")"; } 
+4
source

I have the same problem. Caching does not work, although I set the cacheLength parameter to 1.

With your solution to call the flushCache function after each print period, this works. I could not use:

 if(i === (this.max -1)){ 

since "i" was, for example, 1 after filtering, but "this.max" is still 25, since the original backend request resulted in 25 returned rows.

However , this error ONLY appears when entering words containing Swedish characters "å", "ä" or "ö". So, perhaps cashing works as expected, but not with these special characters.

Anyway. the solution for me was to always call the flushCache control in the formatItem () function:

 function formatItem(row, position, n, term) { if($("#keywords-h").length > 0){ $("#keywords-h").flushCache(); } // format Item return "<span>" + row[0] + "</span>"; } 

Hope this helps someone, and if someone is having the same problems with special characters, send an answer.

+1
source

Obviously, 18 months have come to this, but

cacheLength: 0

in the settings for me. Maybe the latest release fixed the bug?

+1
source

It worked for me.

 function requestData(q) { if (!options.matchCase) q = q.toLowerCase(); //-- I turned off this line // var data = options.cacheLength ? loadFromCache(q) : null; //-- And added this line of code var data = null; 
+1
source

There is an option to disable a subset, for example,

 $("#query").autocomplete( url, { matchSubset: false } ) 
0
source

All Articles