cancel
Showing results for 
Search instead for 
Did you mean: 

Need to resolve multiple calls for same web service

qsdmv
Champ in-the-making
Champ in-the-making
I have page consisting of five regions. Three regions were designed for three webscripts but those webscripts all call one service to return json feeds but use different part of feed. You might be wondering why they are not merged as one component. But I can't since they render in very complex order. Is there a way to call just once from JS file and save this module data for those webscripts to avoid multiple calls. What is the best practice for this? Thank you in advance
3 REPLIES 3

afaust
Legendary Innovator
Legendary Innovator
Hello,

what kind of calls are you making? As long as you are making GET requests with the exact same URL from different component web scripts there is already some caching going on under the covers as long as you use the RequestCachingRemoteConnector (which is the default for the "alfresco" connector in Alfresco Share). If using a different part of the feed results in different URLs for the remote calls, then you might want to try generalizing the requests so that they can get their data from one common request and each perform the same type of request, no matter which is rendered first.

Regards
Axel

qsdmv
Champ in-the-making
Champ in-the-making
First of all, thank you so much for your comments. Here is the example:

Let us say that I have two components. I have defined two js files. One with the following code:

    var profile = eval('(' + service.getProfile(name) + ')');
    model.lastName = profile["lastName"];

Another one is:

    var profile = eval('(' + service.getProfile(name) + ')');
    model.firstName = profile["firstName"];


I don't want: var profile = eval('(' + service.getProfile(name) + ')'); called many times (inside this service, it processes the complex logic and need to access outside URL. As we know, this variable "profile" only is available to specific component. How could we share this variable. This example doesn't demonstrate the complexities. I could create another interceptor so that I can save this object and share with all of pages but this is not what I want. I am trying to find the best way. I am using Surf but not Share.

Thanks again

afaust
Legendary Innovator
Legendary Innovator
Hello,

in pure Surf you should be able to manually cache / interchange objects between components using the RequestContext, which is available in JavaScript controllers as a ScriptRenderContext under the root-scope variable "context". Simply using
context.setValue("profile", profile)
and
var profile = context.properties["profile"]
should suffice.

Regards
Axel