Best practice for logic + db operations + external api call flow

I need to implement following flow, what would be the best practice for this?

client asks for some data, dreamfactory checks from the db if the requested data exists and up to date, if yes serve the data to the client, if not then check for up to date data from an external api, save it to the local db and serve to the user.

i tried external api call and custom services, but i couldnt figure out what would be the best practice to implement this flow as i am beginner to dreamfactory.

I think of implementing the whole logic in a custom scripting service but i couldnt see samples about making external api calls and db operations with custom scripting.

Thanx

Hello, the data to be preserved in this “cache”, must be processed by script or are the raw data of your existing API?

Hi juniorconte, the data must be processed by script when requested by the client. Not sth like raw data migration.