0

I am using this autocomplete plugin (FCBautocomplete). with every character I enter to the field to get the results back, one request is sent to server. Since my data is too big, I am concerned about all the memory crashes that might happen and also the time. say if I have a contact named 'John Smith' there will be 10 requests sent (with all the result back and then result will be displayed based on my chars entered) which is too expensive. Now my question is how does cache help me? Would it be possible to cache the JSON response and get the rest of the search result from that cached response (i.e user enters the first char and all the result will be generated as a JSON response, when the user enters the second char and the rest of chars, instead of sending another request, it searches from the cached JSON response).

Please let me know a good solution for this issue as I am concerned about the performance. Thanks

ComeRun
  • 921
  • 1
  • 20
  • 38
  • Why don't you use jQuery's built-in autocomplete? It has caching ready-to-use :) http://jqueryui.com/autocomplete/#remote-with-cache – XCS Apr 12 '13 at 07:57
  • I have already worked on this great plugin based on my needs. so please let me know if you have a good answer for my issue, thanx – ComeRun Apr 12 '13 at 07:58

2 Answers2

0

You try this code on the ajax call.

    var cache = {};
$.ajax({
    url : ajax.url + '&suggestions=' + $.trim(queryText),
    type : 'POST',
    dataType : 'json',
    success: function(data){
        if(data.value.length > 0){
            addItemFeed(data, etext);
            cache = data;
            bindEvents();
        }else{
            feed.hide();
        }
    }
});

just assign one object named as cache and put your data on the cache and try to access this result anywhere on the page to avoid unwanted ajax call.

Hope this helps...!!!

Ramkumar
  • 446
  • 1
  • 14
  • 30
-1

Defining a global variable in javascript can solve your query.

window.AutoCompleteCacheVariable = "";
Mayank
  • 1,351
  • 5
  • 23
  • 42