I have a controller, which load huge data when controller load, but I do not want to fetch this data again and again when controller is loading. It will load only when the same data is modify or edited. here I am giving a scenario :
我有一个控制器,它在控制器加载时加载巨大的数据,但是我不希望在控制器加载时一次又一次地获取这些数据。只有当相同的数据被修改或编辑时才会加载。这里我给出一个场景:
i have a controller listController
when it load it fetch huge data from database. and it shows list of data in corresponding page(list.html). now when
我有一个控制器listController当它装载它从数据库获取巨大的数据。它显示相应页面的数据列表(list.html)。现在,当
-
I move some other page and again move to same page(list.html). In this case controller will again load and will fetch huge data, but I don't want to load this huge data. I want old data because it delays fetching data from DB and data is same not modified.
我移动了另一个页面,然后再次移动到相同的页面(list.html)。在这种情况下,控制器将再次加载并获取大量数据,但我不想加载这些巨大的数据。我想要旧数据,因为它延迟从数据库中获取数据,而数据也没有被修改。
-
There is option for edit list of data. When I edit the same data(it is under different controller) and save. In that case it will redirect to list.html page and should be load huge data(because in this case data is modified).
可以选择编辑数据列表。当我编辑相同的数据(它在不同的控制器下)和保存。在这种情况下,它将重定向到list。html页面,应该加载巨大的数据(因为在这种情况下数据被修改)。
I searched a lot i got that service is a good option for this, but is there any other way to do that. Is cache is good way to handle this ?
我搜索了很多我得到的服务是一个很好的选择,但是还有其他的方法吗。缓存是处理这个问题的好方法吗?
Thanks !!!
谢谢! ! !
2 个解决方案
#1
1
Mind advises to use pagination to prevent unnecessary pauses. Pagination is a common approach for distributed applications with massive data.
Mind建议使用分页来防止不必要的停顿。分页是使用大量数据的分布式应用程序的常见方法。
However if you find yourself still looking for a persistent client-side storage examine angular local storage
但是,如果您发现自己仍然在寻找一个持久的客户端存储,检查角度本地存储。
#2
1
One thing you can do is store the data in some parent controller, rather then listController( so that data is not fetched again on reload of list.html) and fetch data from this parent controller .
您可以做的一件事是将数据存储在一些父控制器中,而不是在listController中(这样数据就不会再次从list.html的重载中获取),并从这个父控制器获取数据。
you should use cache also like:
你也应该使用缓存:
$http.get(url, { cache: true}).success(...);
- this will cache the response.
美元http。get(url, {cache: true}).success(…);-这将缓存响应。
You can custom implement it yourself using $cacheFactory .
您可以使用$cacheFactory自定义实现它。
But its always better to store data in some database server (use mongodb for instance, its really smooth)
但是在某些数据库服务器中存储数据总是更好的(例如,使用mongodb,它非常平滑)
#1
1
Mind advises to use pagination to prevent unnecessary pauses. Pagination is a common approach for distributed applications with massive data.
Mind建议使用分页来防止不必要的停顿。分页是使用大量数据的分布式应用程序的常见方法。
However if you find yourself still looking for a persistent client-side storage examine angular local storage
但是,如果您发现自己仍然在寻找一个持久的客户端存储,检查角度本地存储。
#2
1
One thing you can do is store the data in some parent controller, rather then listController( so that data is not fetched again on reload of list.html) and fetch data from this parent controller .
您可以做的一件事是将数据存储在一些父控制器中,而不是在listController中(这样数据就不会再次从list.html的重载中获取),并从这个父控制器获取数据。
you should use cache also like:
你也应该使用缓存:
$http.get(url, { cache: true}).success(...);
- this will cache the response.
美元http。get(url, {cache: true}).success(…);-这将缓存响应。
You can custom implement it yourself using $cacheFactory .
您可以使用$cacheFactory自定义实现它。
But its always better to store data in some database server (use mongodb for instance, its really smooth)
但是在某些数据库服务器中存储数据总是更好的(例如,使用mongodb,它非常平滑)