Caching values in service and browser refresh

Showing 1-3 of 3 messages
Caching values in service and browser refresh bsr 6/28/12 1:46 PM
With the help of community and the tutorials, I learned how to use session to encapsulate data and inject into various controllers. Now, in my application, I am trying to cache a request like below

angular.module('myApp.services', ['ngResource']).
    factory('Play', function($resource, $routeParams){
        var Play = {
            resource: function() {
                return $resource('/api/Play/:_id', {} )
            } ,
            initplay: $resource('/api/Play/:_id', {} ).get({_id:$routeParams._id})
        };


        return Play
});

initplay is initialized correctly and I could share it across controllers. Now, if I navigate away to other views, it all works till I refresh the browser window. The problem is that in some views I don't keep _id as part of url anymore. Is this a bad practice, or how should I handle this.

Re: Caching values in service and browser refresh Dan Doyon 6/28/12 2:40 PM

below I use query to get llist of messages, for saving I pass in a messageId when I call it.    

 .factory('FooSvc', function ($resource) {

        return $resource('../foo/messages/:messageId', { format: 'json' }, {

              'query' : { method: 'GET', isArray: false },

              'save' : { method: 'PUT', params:  { messageId:'@messageId'} },

        });

    })

-- controller snippet

     var somelist = Foo.query(); 

     foo.save({messageId: 123});

Am I missing something?

Re: Caching values in service and browser refresh bsr 6/28/12 5:01 PM
Thanks Dan. I was trying to avoid query() every time when I navigate to different views.

Say I have a window, where the user makes some selections based on the data (retrieved through messageId).
Now, I need to show a confirmation window based on previous step [assume this is not trivial to just show a pop up].
For the new screen, I may have to pass all the data though url. If I save it in $session, if the user refresh the browser, those values are no longer available.

 I may not have a choice other than passing the messageId through url or show the next screen as a modal window.

Like to know your suggestion.