Search code examples
looker-studio

Multiple chart caching


Setup: I have created a data studio connector that connects to an API that I uses to graph charts on data studio reports. I have setup the getData() method to check the cache for the data before requesting it from the API. If it's not cached fetches the data and then caches it.

Issue: I have multiple charts on the report with the same metric. Each chart will call the getData() method at the same time on initial load of the page. Since they all happen at the same time no data is cached yet. Each getData() method call thinks it's the first time of this bit of data being fetched. So even though I'm caching the data it can't use the cached data since they are being called at the same time.

Is there any way to get around this? Is there a way to have the charts synchronous call the getData() method?

Here is some output from the getData() method. I have two charts setup with the same metric on each chart. If they were called any bit apart the second chart would be cached.

Chart 1:
Dec 15, 2020, 12:26:32 PM Debug => NOT CACHED | key: fKes4 | timestamp: 2020-12-15T18:26:32.647Z
Chart 2:
Dec 15, 2020, 12:26:32 PM Debug => NOT CACHED | key: fKes4 | timestamp: 2020-12-15T18:26:32.799Z

Solution

  • AFAIK, this is not possible. All visuals in your report will call getData at the same time and it is supposed to be asynchronous.

    However, supposing you can change the called API, you may workaround this behavior modifying the called API to don't let it answer more than one API call at once. This way, the second call of your getData function may wait for the cached content made by the first call. I'll not say this is an improvement or it worth the effort, but it will certainly do the job.

    My suggestion is to not use Community Connectors to integrate Data Studio with APIs. Create a Cloud Function to consume your APIs and store the data in BigQuery, it will be easier to maintain and much more performatic.