Angularjs keep $http result cached

Asked

Viewed 369 times

0

Good people, next, I’m putting together an application that involves a lot of navigation and data visualization. It would go something like this:

There is a customer table (+500 registered) with approx. 35 columns of informative data per customer. In addition, there is the view of processes, service orders, etc. All of them are generated based on clients.

The system usage flow involves a lot of navigation enters these views. For example:

Access clients -> select one of them -> view their service orders -> go back to customers -> view another client -> If you enter new order, access the service order view, etc...

For each of these views I make one $http where I take a list of customers, a list of processes, or a list of service orders, depending on the view.

The request is done with a simple code, through a Factory

//factory
getCliente: function() {
    return $http.get("api/func.php?action=get_cliente").then( 
        function(res) { return res.data;},
        function(err) {alert(feedbackError);}
    );
},

//controller
factCliente.getCliente().then(function(res) {
    $scope.detcliente = res;
});

These lists may change, or receive new data, but the frequency with which this happens is much lower than the frequency with which the user needs to navigate.

The problem

The application is starting to get slow at the time of displaying the views. Around 1-2s delay (because depending on the view, involves a combination of sql to get the list - In this area, we have no more way to move).

We cannot generate the list and save to a file .json (as we did before) because some data is confidential, so only the logged in user can view.

Doubt

What could be done to solve this problem? I am currently using a limitTo:50 that helps a little, but it has some limitations, for example: If the table displays only 10 records and the user tries to filter it through a text field, the other results will not appear on the screen (at least not as is for now).

Is there any way to keep the data cached in Angularjs to facilitate performance with the use of $http?

  • Comrade, I don’t know the context of your project. The problem seems to be more backend than frontend. Can you measure that? You need to see if the backend that is slow or if when receiving the data the angular is taking for some reason. The fact is that as the volume of data is large, you made a good choice using angular. But you also need to see if you are making use of the framework in the right way.

  • Yes, actually I imagine it’s something in Angularjs, because if I put a limitTo:5 the table appears instantaneously, but when I let it free it ends up having this delay. The biggest problem is that I know that the client already has 500-600 more customers to register, because it is migrating his system. Then it’s gonna get worse'.

  • Okay, have you ever thought about using scroll-infinity? Here’s an example: http://jsfiddle.net/wesjones/sqas5wjp/. If you need it, I have font on the simplest github. Wheel with java + Rest

  • It’s what I had in mind. But it would create the same limitation problem, wouldn’t it? That is, if you start the view with 10 (for example) and I use the text search filter, will it show the rest? Or more than 10 results?

  • So it depends on how it is implemented. You can pass a value. Start=0, End=10, first query, Start=10, End=20 in second and Start=20, End=30 in third. So on. And on your backend side you will use these start and end values to go paging. What runs in your backend? If java see: https://github.com/emirdeliz/meus-projetos/tree/master/scroll-infinito-angular-rest-datafactory

  • Why not continue saving the information in . json or Web Sql, and delete whenever the application is opened or user depress? Thus, it would continue to be restricted to this user.

  • The problem with this is that, since it is of constant use, that is, it has the workflow of the company there, it would be the json while the person was online - Business hours. And that’s what I want to avoid, not leave the json with the data on the server. What would be Websql?

  • @Emirmarques At the moment my be is in mysql. I think I will make a filter for the table, with display buttons 5 - 10 - 50 - all and use the limit. Infinite scroll is also interesting, but in this case, as there is a lot of information, I think it will be the best way out.

  • Plus which language links the database to the angular?

  • php, with mysql server

Show 5 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.