Refreshing Cache for a Module Query After Creating a New Client

  • Goal: I need to refresh the cache of a query resource in a header module on Retool, which retrieves a list of my clients. This list should be updated across all pages using this header immediately when a new client is created on one of the pages.

  • Steps: I followed a method from the Retool forum for triggering a query in a module from the parent app. Here’s what I did:

    • Created an input variable in the header module.
    • Set a standard variable on the client creation page to NULL, which gets updated with Date.now() when a new client is created.
    • Used this variable as a trigger in the module for a "Query JSON With SQL" to refresh the client list.
    • Despite these configurations, the query executes with cached data instead of fetching new data.
  • Details: Here is a snippet of the query configuration in the module:

    select * from {{ refresh_companies.values }};
    

    The refresh_companies.values is supposed to receive the value of Date.now() when a client is added, triggering the query with updated criteria. However, the query still seems to return cached results.

  • Screenshots:

Hey @Leo_Lhuile - thanks for reaching out.

As you've discovered, there isn't a very elegant way to trigger a query that resides within a module. If I understand correctly, you're successfully triggering the query but it's not invalidating the cache - do I have that right? Does the debugger show that the get_companies query runs when you expect it to?

I did a little bit of testing and the cache is definitely being cleared, as subsequent requests return the updated data, but it seems that it's being cleared asynchronously. The result is that immediately triggering the query after invalidateCache still retrieves cached data. I'll dig into this a bit more and hopefully get back to you with a fix tomorrow!

After some further investigation, I'm pretty confident this could be classified as a bug. Executing triggerQuery from within the module:


Executing triggerQuery from the parent:


The root cause seems to be that the invalidateCache request goes to a different endpoint depending on whether it's triggered from the parent or module:

As far as workarounds go, nothing very simple comes to mind. You might technically be able to construct the POST request manually but that doesn't sound like a great option. :sweat_smile: I'll talk to our team about getting eyes on this and will provide an update here as soon as possible!

Thank you, Darren, for shedding light on this issue. I agree that it seems to be a bug and I appreciate your plans to discuss this with your team. I'll be waiting for any updates or solutions regarding this matter. Thanks again for your prompt assistance! :slight_smile:

1 Like

Any update on this? I'm having the exact same issue.

1 Like

Hi @allenatbluestone! Welcome to the community. :slightly_smiling_face:

I don't have any particularly impactful updates, unfortunately, but can share that we are planning to do some extended work on modules in the relatively near future. This specific issue is on the team's radar and should hopefully be part of that work!