Angular $http service cache not working properly

I have a $http service in angular js which has a cache enable for it. When first time load the app service gets call and get cache. Now when i call the service anywhere from the same page the data comes from cache but when i change the page route and again call the service from another page the data come from server(i am just changing the route not refreshing the page)

Edit => Code was working !! On route the data also came from cache but it took more time as there are few other call as. It just took more time then i accepted the cache to respond .If i call same from any click event then it will take 2ms to 3ms

here is my service

commonServicesModule.service('getDetails', ['$http', 'urlc',
    function($http, urlc) {

        return {
            consumer: {
                profile: function(id) {
                    return $http({
                        url: urlc.details.consumer.profile,
                        cache: true,
                        params: {
                            'consumer_id': id,
                            'hello': id,
                        },
                        method: 'GET',
                    }).success(function(result) {
                        return result;
                    });
                },

            }
        }
    }
])

Call from controller :

start = new Date().getTime();
            /*get user information */
            getDetails.consumer.profile('1').then(function(results) {

                console.log('time taken for request form listCtrl ' + (new Date().getTime() - start) + 'ms');
            });

when i call this from anywhere else after route it take the same time.

Answers


Try moving the consumer object into the body of the function, and return a reference to it, like so:

commonServicesModule.service('getDetails', ['$http', 'urlc', function($http, urlc) {

    var getConsumer = {
        profile: function(id) {
            return $http({
                url: urlc.details.consumer.profile,
                cache: true,
                params: {
                    'consumer_id': id,
                    'hello': id,
                },
                method: 'GET',
            }).success(function(result) {
                return result;
            });
        }
    };

    return { consumer: getConsumer };

}]);

Need Your Help

uninitialized constant ActiveSupport::EventedFileUpdateChecker (NameError) - [learn-ruby-on-rails] Tutorial

ruby-on-rails

I'm following the book "Learn Ruby on Rails" by Daniel Kehoe. I can't seem to get past the end of Chapter 10, start of Chapter 11, where I start the application server following the changes within