How to cache data from webservice?

Hi,
I have 2 dropdowns on my screen, on change of the 1st dropdown value I am calling a webservice to populate the data in 2nd dropdown. I want to reduce these rest calls, How can I implement caching for this?
I also have the same dropdowns on 2 more screens.
I have read about Cache in minutes property, but not sure about how to use it.
Any help would be great.

Thanks,
Anagha

Solution

Hi Anagha,

You can put the call of the webservice in a Server Action and set the Cache (in minutes) of the Server Action.
Just set the value in minutes that you want the response of the Server Action to be in the cache.

Cheers.

Solution

Eduardo Jauch wrote:

Hi Anagha,

You can put the call of the webservice in a Server Action and set the Cache (in minutes) of the Server Action.
Just set the value in minutes that you want the response of the Server Action to be in the cache.

Cheers.

Hey,
I did this, I set the minutes to 30.But everytime I change the dropdown response I get the value of CacheHit as false.
Am I doing something wrong?


Thanks

Anagha Chikate wrote:

Eduardo Jauch wrote:

Hi Anagha,

You can put the call of the webservice in a Server Action and set the Cache (in minutes) of the Server Action.
Just set the value in minutes that you want the response of the Server Action to be in the cache.

Cheers.

Hey,
I did this, I set the minutes to 30.But everytime I change the dropdown response I get the value of CacheHit as false.
Am I doing something wrong?


Thanks

Hum...

First thing, is your stack Dot Net or Java? If it is Java, there is no Built In cache for Java, so the Cache property will not work. I think there are applications in the Forge to help in those situations, but I am not qualified to help.

If the stack is Dot Net, than I would start asking myself if I am passing different arguments for the action. If I am, than the cache will not work (afaik), because different input parameters can potentially return different things so the action is executed.

Cheers.

Eduardo Jauch wrote:

Anagha Chikate wrote:

Eduardo Jauch wrote:

Hi Anagha,

You can put the call of the webservice in a Server Action and set the Cache (in minutes) of the Server Action.
Just set the value in minutes that you want the response of the Server Action to be in the cache.

Cheers.

Hey,
I did this, I set the minutes to 30.But everytime I change the dropdown response I get the value of CacheHit as false.
Am I doing something wrong?


Thanks

Hum...

First thing, is your stack Dot Net or Java? If it is Java, there is no Built In cache for Java, so the Cache property will not work. I think there are applications in the Forge to help in those situations, but I am not qualified to help.

If the stack is Dot Net, than I would start asking myself if I am passing different arguments for the action. If I am, than the cache will not work (afaik), because different input parameters can potentially return different things so the action is executed.

Cheers.

The stack is .Net
I have only 3 values in dropdown 1 and around 100's of values in 2nd one which does not change very often.
When I executed my flow, the debugger doesn't go into the server action where the web service is called for the cached dropdown 1 value. But my concern is that the CacheHit value is false all the time, So how should I confirm the caching is working or not?

 


Anagha Chikate wrote:

Eduardo Jauch wrote:

Anagha Chikate wrote:

Eduardo Jauch wrote:

Hi Anagha,

You can put the call of the webservice in a Server Action and set the Cache (in minutes) of the Server Action.
Just set the value in minutes that you want the response of the Server Action to be in the cache.

Cheers.

Hey,
I did this, I set the minutes to 30.But everytime I change the dropdown response I get the value of CacheHit as false.
Am I doing something wrong?


Thanks

Hum...

First thing, is your stack Dot Net or Java? If it is Java, there is no Built In cache for Java, so the Cache property will not work. I think there are applications in the Forge to help in those situations, but I am not qualified to help.

If the stack is Dot Net, than I would start asking myself if I am passing different arguments for the action. If I am, than the cache will not work (afaik), because different input parameters can potentially return different things so the action is executed.

Cheers.

The stack is .Net
I have only 3 values in dropdown 1 and around 100's of values in 2nd one which does not change very often.
When I executed my flow, the debugger doesn't go into the server action where the web service is called for the cached dropdown 1 value. But my concern is that the CacheHit value is false all the time, So how should I confirm the caching is working or not?

 


Well, it is working.

What is not being cached is the request to the server (from the browser). The Server action call is made already in the server. If the server action is not called (and you are seeing this in debug), than it is because the cache is working properly.

Cheers


Eduardo Jauch wrote:

Anagha Chikate wrote:

Eduardo Jauch wrote:

Anagha Chikate wrote:

Eduardo Jauch wrote:

Hi Anagha,

You can put the call of the webservice in a Server Action and set the Cache (in minutes) of the Server Action.
Just set the value in minutes that you want the response of the Server Action to be in the cache.

Cheers.

Hey,
I did this, I set the minutes to 30.But everytime I change the dropdown response I get the value of CacheHit as false.
Am I doing something wrong?


Thanks

Hum...

First thing, is your stack Dot Net or Java? If it is Java, there is no Built In cache for Java, so the Cache property will not work. I think there are applications in the Forge to help in those situations, but I am not qualified to help.

If the stack is Dot Net, than I would start asking myself if I am passing different arguments for the action. If I am, than the cache will not work (afaik), because different input parameters can potentially return different things so the action is executed.

Cheers.

The stack is .Net
I have only 3 values in dropdown 1 and around 100's of values in 2nd one which does not change very often.
When I executed my flow, the debugger doesn't go into the server action where the web service is called for the cached dropdown 1 value. But my concern is that the CacheHit value is false all the time, So how should I confirm the caching is working or not?

 


Well, it is working.

What is not being cached is the request to the server (from the browser). The Server action call is made already in the server. If the server action is not called (and you are seeing this in debug), than it is because the cache is working properly.

Cheers


Thats a great help.
Thanks a lot :-)



You're welcome :)

Hi Eduardo,

I'm really interested in OutSystems Caching.

Could you please help me to understand how we invalidate the cache for web services if there's an update on the database from back-office?

Thanks,

Thang Nguyen


Hi Thang, 

If you set cache for a server action, the only way to invalidate it before the end of the cache period is either calling the action with different input parameters or invalidating the application cache (that you don't want). 

I would say that here you are better setting a smaller interval for the cache, or defining a local cache in the application through the use of database, you keep the required data locally and only update if necessary, a little like it is done in mobile. 

Cheers 

Hi Eduardo,

Thank you very much for your sharing. 

My case will be the REST API communication between the environments and application between OutSystems and the other systems. Do you think it will be the same scenario with web service  for mobile?

Thanks,

Thang Nguyen


Hi,

Not necessarily.
But you need to think in terms of performance, what makes sense for your application.

So, you need to define if it makes sense to have a cache in your OutSystems application (database) that stores the data and that you synchronize with the external APIs from time to time, or if you want to retrieve the information entirely on the fly, and than defined if the Server Action will have cache or not.

But if you want to use a "cache" system and warn the OutSystems application that there is new data available, you may consider the above approach.

Cheers.