Query trigger after invalidateCache() sometimes returns cached query

Hi everyone,

I'm running into a problem where, after submitting data to a Databricks table, I want to display that new data in a table, which initially displayed cached data.

My current setup is:

  1. Databricks Submit Query
  2. Event handler of the submit query triggers a JS query called "Invalidate_cache"
  3. "Invalidate_cache" query runs with this code "return Promise.resolve(My_Query.invalidateCache())"
  4. Event handler of that js query triggers "My_Query.trigger()"

I'd say about 20% of the time this results in My_Query being run from the cache instead of being run "fresh". Any idea why that happens / suggestions to improve my code?

Thanks in advance!

How are you managing the execution order of the event handlers? The order in the UI is irrelevant - they are executed asynchronously. To make sure they all run in the order you want, you need to handle it differently (e.g. here).

Hi @jg80 thanks for the suggestion!

Currently, the submit query runs, in its event handler I run a js script containing the invalidateCache() function on success and in the event handler of that js script, I trigger the new query load "on success". So I though in this case they would not run in parallel.

I'm not super familiar with asynch functions / promises so I wasn't sure how to implement it in my case. I tried putting this in the event handler of the submit query, but it did not work:

"const cacheDeletion = await new Promise((resolve) => {
My_Query.invalidateCache({onSuccess: resolve(My_Query.trigger())})
})"

The way you are describing it (a series of queries chained by event handlers) should also work, but it is also possible that some of these events would return a promise before the action they initiate completes.

Could you share some code and screenshots of your setup without exposing anything you don't want to share? It may help myself and other forum members to help with the issue you are running into.

Sure!

Here is the event handler of the submit query:
submit_trigger

Now, I have actually created an async function in the triggered javascript including a short timeout:
invalidate_cache

But even if I prolong the timeout to 3 seconds, the script does not reliably run the uncached query:


I think you need one more await let newQuery = await Historie_Raw.trigger()