Persisting Cache

55 views
Skip to first unread message

David Wright

unread,
Sep 17, 2013, 11:35:53 AM9/17/13
to ampl...@googlegroups.com
If i use amplify.request and set the cache to persist should the ajax request be persisting on page reloads? That's what I'm trying to have happen but I'm not seeing it. In my test I run an amplify.request call with cache: persist then I change some data on the other end of the ajax call and reload the page hoping the data from amplify doesn't change because it is pulling from the cache but it's giving me the updated info. Let me know if I should post code. :/

Doug Neiner

unread,
Sep 17, 2013, 11:42:38 AM9/17/13
to ampl...@googlegroups.com
Hey David, 

Are you using the full AmplifyJS build that includes amplify.store?

Doug

David Wright

unread,
Sep 17, 2013, 12:45:35 PM9/17/13
to ampl...@googlegroups.com
I am and I can confirm that is working because I'm using it to store login credentials on the same page.

Doug Neiner

unread,
Sep 17, 2013, 12:52:11 PM9/17/13
to ampl...@googlegroups.com
If you could share the request definition, and relevant parts of the actual request, that would probably be helpful.

Doug
--
You received this message because you are subscribed to the Google Groups "Amplify" group.
To unsubscribe from this group and stop receiving emails from it, send an email to amplifyjs+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

David Wright

unread,
Sep 17, 2013, 12:52:53 PM9/17/13
to ampl...@googlegroups.com
code.

amplify.request.decoders.appEnvelope =
  function ( data, status, xhr, success, error ) {
    if ( data.status === "success" ) {
      success( data.data );
    } else if ( data.status === "fail" || data.status === "error" ) {
      error( data.message, data.status );
    } else {
      error( data.message , "fatal" );
    }
  };

amplify.request.define( "account", "ajax", {
  dataType: 'jsonp',
  contentType: "application/jsonp; charset=utf-8",
  url: url,
  processData:false,
  cache: "persist",
  decoder: "appEnvelope"
});

amplify.request({
  resourceId: "account",
  success: function( data ) {
    //stuff happens here
    //do i need to do anything amplify specific here?
  }
});

Doug Neiner

unread,
Sep 17, 2013, 1:08:39 PM9/17/13
to ampl...@googlegroups.com
Ah, I wondered if was a JSONP request. There is an open pull request I need to merge (doh) that would fix this for you: https://github.com/appendto/amplify/pull/86.

The issue is due to the pieces jQuery adds to the JSONP url: the random callback method, and an actual cache buster. This makes the URL not match what is in the cache.

Anyway, I reviewed that existing pull request and am going to talk to the developer today about a possible bug in his fix. You are welcome to pull from his fork in the mean time and see if it fixes your problem (It should).

The other way to fix it is to add jsonpCallback: "someFunctionName" which will cause the callback to stay the same on each request, allowing the caching to work.

Doug
--

David Wright

unread,
Sep 17, 2013, 1:11:58 PM9/17/13
to ampl...@googlegroups.com
Awesome! Thank you, Doug!



--
You received this message because you are subscribed to a topic in the Google Groups "Amplify" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/amplifyjs/jFmv8N8pIhM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to amplifyjs+...@googlegroups.com.

Doug Neiner

unread,
Sep 17, 2013, 2:53:34 PM9/17/13
to ampl...@googlegroups.com
I just merged in that pull request into the main branch. Feel free to pull from master on Github and let me know if it fixes your issues. The still links to an older version.

Doug

David Wright

unread,
Sep 17, 2013, 2:54:24 PM9/17/13
to amplifyjs
hah, I was just replying to tell you I was still struggling. I'll give the latest a go.


On Tue, Sep 17, 2013 at 1:53 PM, Doug Neiner <dne...@appendto.com> wrote:
I just merged in that pull request into the main branch. Feel free to pull from master on Github and let me know if it fixes your issues. The still links to an older version.

Doug

--

Doug Neiner

unread,
Sep 17, 2013, 3:02:26 PM9/17/13
to ampl...@googlegroups.com
Feel free to hit me up directly on Skype: Pixelexperience and we can try to solve it if this doesn't work for you.

Doug
You received this message because you are subscribed to the Google Groups "Amplify" group.
To unsubscribe from this group and stop receiving emails from it, send an email to amplifyjs+...@googlegroups.com.

David Wright

unread,
Sep 23, 2013, 5:38:36 PM9/23/13
to ampl...@googlegroups.com
Since this was resolved on Skype I thought I'd document it for any future people.

There was a jsonp bug. Doug Neiner fixed it and it shouldn't be a problem anymore.


On Tuesday, September 17, 2013 10:35:53 AM UTC-5, David Wright wrote:
Reply all
Reply to author
Forward
0 new messages