need help with actions and hooks

my actual question is :
I have a plugin with add_shortcode method, I get information from another website using api and pass them in a function to use them in add_shortcode method, my question is can I send only 1 request to that api page and save the value in memory so for each shortcodes I don’t have to call a curl. (shortcodes using attr Parameters, I mean i send value to add_shortcode method)

You could cache the API data in memory locally and have your shortcode handler fetch data from cache instead of using the API over and over again. You can use the WP_Object_Cache if the data is only needed for the current request. If the data needs to persist between requests, use session vars or cookies if the data is for a specific user. If more generic data needs to persist between requests, you can store data short term in the DB as a transient.

Source link