After next(Route) to other page, come back it still call back the link. How to cache JSON data from http call to optimize performance?
Try some solution but not working
$http.get(url, { cache: true}).success(...);
Any better solution to this?
After next(Route) to other page, come back it still call back the link. How to cache JSON data from http call to optimize performance? Try some solution but not working
Any better solution to this? |
|||
Better way is to make
|
|||
|
You can also use angular-data directive for caching. It allows you to specify where caching : local storage / session / memory, and you can set the time you want to keep your requests in cache. http://angular-data.pseudobry.com/documentation/guide/angular-cache/index To initialize the cache, add this code in a app.run() function :
And then use it in your code like you did :
|
|||
|
I recommend to you download angular-cache! It is a very useful replacement for Angular's $cacheFactory Inside a .run() block, define your cache:
Then inside your Service you can manage how to use your data, get it from Cache when it expires, make a new call and refresh data.
That´s all! |
||||
|
return cachedPromise || cachedPromise = $http.get(url)...
– PSL Aug 10 at 3:57