Fetch data only once on application start

Fetch data only once on application start

  

Hi,

In a web application I want to fetch data once (and fill a structure that must keep its data during the session) on a list screen which is also the entry point of the application. How do I prevent fetching the data more than once (going back from the detailscreen to the listscreen wil trigger the prepariation action, zo I guess that's not the proper place)?. 

Regards, Harry

 .  

Hey Harry


Not sure if I understood your problem completely, but I think you can check if the structure where you store the data is empty. This way, your flow should only call the data fetching queries if the structure is empty


Regards,

Ângelo

Solution

Hello,

If your concern is performance and want to use cache as soon as possible for the user session, you just need an identification for that specific session, to be the input of a cached action that retrieves the information you need. If that action has cache for some period of time (Eg: 20m), you will disable it everytime you change the input value (change your session). Having that in mind, in this way you don't execute the query everytime you use the action to get that values :)

Kind regards

Solution

Hi Miguel,

Thanks for pointing this out. I have more than one aggregate on a preparation screen, but I see now that I can cache a specific aggregate for a give time.

Regards, Harry 

Hi Harry,

Another option (if applicable) is to do it OnSessionStart:

André Rodrigues wrote:

Hi Harry,

Another option (if applicable) is to do it OnSessionStart:

Thanks André. OnSessionStart can be added to my strategy with the cached action :) But check if you have an userId before fetching the first data. Because the session doesn't start only after the login.

Regards


Hi

In an onSessionStart I put an SQL with a structure. Now I want to point a combobox in a screen to this structure (use it as source). I cannot choose the structure it seems. Can I not use it this way?

Regards, Harry 

Harry de Boer wrote:

Hi

In an onSessionStart I put an SQL with a structure. Now I want to point a combobox in a screen to this structure (use it as source). I cannot choose the structure it seems. Can I not use it this way?

Regards, Harry 


Queries in "OnSessionStart" are outside of the scope of screens and web blocks. That is not a good solution for this, unless you put the query in an Action, cache the query within the action, then call the action from session start. That will force it to run the query and cache it. But that cached value will be shared among sessions, so it's not a great approach unless you pass the current user id into the query as a parameter to force it to cache each user's view of the data differently. Either way, I feel that this is a bad approach. If this is a query you want to run infrequenrly, just use caching on the query wherever it naturally resides.


J.Ja

Thank you for the explanation Justin. Regards, Harry