S
S
Sergey Nikolaev2015-07-23 20:40:18
JavaScript
Sergey Nikolaev, 2015-07-23 20:40:18

How to properly cache in Angular?

Is it correct to cache the request like this or is there a smarter practice?

// фактори в которой определяем кеширование
function datacache($cacheFactory) {
        return $cacheFactory('megaCache', {});
}
// запрос
function money(){
            var name = 'money';

            var data = datacache.get(name);
            if(data){
                return data;
            }
            return req.option('money').then(function (res){
                datacache.put(name,res);
                return res;
            });
        }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2015-07-23
@Devastor

https://docs.angularjs.org/api/ng/service/$http#caching
in general, it seems to be normal, the only thing that I would immediately put a promise in the cache is that all the other dudes would also wait and not pull again apishka.

F
faragly, 2015-07-23
@faragly

I implemented query caching in the same way, it's a good option.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question