S
S
Sergey Nikolaev2015-12-17 15:14:06
JavaScript
Sergey Nikolaev, 2015-12-17 15:14:06

How to put data into Angular's $http cache?

Good afternoon, in Angular, requests have a very convenient cache parameter.

$http.get('api',{
    cache: true
}

How to write data to this cache before the request is executed, so that the request would not be executed even for the first time, but already had cached data?
PYSY: I don't need to talk about such approaches. I want to put the data exactly in the $http cache. Thanks
var dataCache = $cacheFactory.get('Cache');  
$http.get('api',{
    cache: dataCache
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Nikolaev, 2015-12-17
@Devastor

And the casket just opened.

//формат данных кеша, где data массив с данными
var cache = [
 200,
 data,
 {"content-type": "application/json"},
 "OK"
]
//url - полный путь запроса
$cacheFactory.get('$http').put(url, cache);

A
Anton, 2015-12-18
@brud

If I'm not mistaken, then you should read about mock objects)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question