In my Django web application i have this function that makes a request to google's youtube api, this function gets excuted each time a user submits a form Here is the code:
import googleapiclient.discovery
def myFunc():
youtube = googleapiclient.discovery.build(
api_service_name, api_version, developerKey=api_key)
request = youtube.search().list(
part="id",
maxResults=25,
q="surfing",
)
youtube_api_response = request.execute()
for object in youtube_api_response["items"]:
# my logic here
Now building the api client using
googleapiclient.discovery.build(api_service_name, api_version, developerKey=api_key)
So building this way each time a user submits a form will require a lot of time and slow down the website. Is there a way to store this build somehow or reuse the same one each time without the need of building again and again to improve the performance.