Reputation: 13826
So I have an endpoint which returns the contents of many entities in parallel.
I have a shared service which calls this endpoint and puts them into a shared $cacheFactory
.
When GET /base_entity/<id>/all
route is hit first, then GET /entity/<id>
should return the cached copy.
What's best-practice in telling the GET /entity/<id>
service to not perform an HTTP get until GET /base_entity/<id>/all
has had a chance to complete?
$broadcast
/$emit
approach seems odd. I suppose I could use that shared $cacheFactory
with cache.put('START /all for ID:' +, id)
and cache.put('FIN /all for ID:' +, id)
, but not sure if that's a strange way of solving the problem.
Upvotes: 0
Views: 41
Reputation: 13826
Ended up creating a new view and controller. The controller's constructor
calls GET /base_entity/<id>/all
and caches it then does a $state.go
passing along current $stateParams
. Concurrently the view shows a shiny graphic loading directive
.
Now when /entity/<id>
state is transitioned to, the service first checks ALL cache; updates its cache accordingly; then checks cache and returns that in a $q
promise, or hits $http
otherwise.
Upvotes: 0