Caching results from Ajax

Limor Messika's Avatar

Limor Messika

20 May, 2011 01:43 PM

At the moment I have the code running and all is well:
$("#name").autoSuggest('socialAuth/twitterContacts.jsp', {selectedItemProp: "name", selectedValuesProp: "value", searchObjProps: "name"}); But..I am trying to cache my results, so that I have less hits on the server, I was thinking to cache the the results as they are not that many on server side and then just use that as my json source, but being a newbie I am probably doing it wrong.
So..I tried this:
var cache = {}];

var getPage = function(){

if(cache){
    //content is already in cache, use it from there
    return cache;

}
else{
    //object with parameteres sent with GET request

    $.ajax({
      url: "socialAuth/twitterContacts.jsp",
      cache: false,
      success: function(response){

            //store the response in the cache for later use
        cache = response;
       return cache;
      }
    });
}

}; $("#name").autoSuggest(getPage', {selectedItemProp: "name", selectedValuesProp: "value", searchObjProps: "name"}); But I just get no results...

I would really appreciate if someone could assist me with this...Thanks in advance for checking out!
Limor

  1. 1 Posted by tushar on 27 Jun, 2011 09:15 AM

    tushar's Avatar

    Hey all,

    It seems that there has been no response to this question. Limor : Have u resolved this issue if yes could u please post the solution as i am trying to achieve the same and have no leads as such..
    also if any other member can answer that would be great.
    Regards,
    Tushar

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac