Bug? Results Cached on Action Formula

I’ve built a simple Pack to generate a UUID using Xano:

The issue is that the result from Xano UUID pack is being cached.

It’s an action formula so that shouldn’t happen, but adding cacheTtlSecs: 0 to the formula didn’t fix it either.

I’ve confirmed that a new UUID is generated every time I request the endpoint using postman.

What am I doing wrong?

import * as coda from "@codahq/packs-sdk";
export const pack = coda.newPack();

pack.addNetworkDomain("xano.io");

// This line adds a new formula to this Pack.
pack.addFormula({
  name: "UniqueID",
  description: "Returns a unique ID using UUID v4.",
  parameters: [], // No parameters required.
  resultType: coda.ValueType.String,

  isAction: true,
  cacheTtlSecs: 0, // Disable formula caching

  // This function is declared async to that is can wait for the fetcher to
  // complete. The context parameter provides access to the fetcher.
  execute: async function ([], context) {
    let url = url;

    // The fetcher's fetch method makes the request. The await keyword is used
    // to wait for the API's response before continuing on through the code.
    let response = await context.fetcher.fetch({
      method: "GET",
      url: url,
    });

    // The API returns an array of strings, which is automatically parsed by
    // the fetcher into a JavaScript object.
    let thisID = response.body;

    // Return the paragraphs separated by a blank line.
    return thisID;
  },
});

Found a solution for those facing a similar issue.

Added Now() as a queryparam so the URL was always different.

pack.addFormula({
  name: "UniqueID",
  description: "Returns a unique ID using UUID v4.",

  parameters: [
    coda.makeParameter({
      type: coda.ParameterType.String,
      name: "now",
      description: "Provide Now() as the value.", //Make formula volatile?
    })
  ],
  resultType: coda.ValueType.String,

  isAction: true,
  cacheTtlSecs: 0, // Disable formula caching

  // This function is declared async to that is can wait for the fetcher to
  // complete. The context parameter provides access to the fetcher.
  execute: async function ([now], context) {
    let url = coda.withQueryParams(url, {now: now})

    // The fetcher's fetch method makes the request. The await keyword is used
    // to wait for the API's response before continuing on through the code.
    let response = await context.fetcher.fetch({
      method: "GET",
      url: url,
    });

    // The API returns an array of strings, which is automatically parsed by
    // the fetcher into a JavaScript object.
    let thisID = response.body;

    // Return the paragraphs separated by a blank line.
    return thisID;
  },
});

Pack for those curious to try it out: Xano UUID Pack, extend Coda with Xano UUID | Coda

1 Like

Hi @Brian_Sowards - I think the root cause here is that Coda caches formula results and fetcher responses. Applying cacheTtlSecs: 0 on the formula causes it to be rerun every time, but then the fetcher will return the cached response from the server. You can disable caching in the fetcher using the same technique:

pack.addFormula({
  //... 
  cacheTtlSecs: 0, // Disable formula caching

  execute: async function ([now], context) {
    // ...
    let response = await context.fetcher.fetch({
      method: "GET",
      url: url,
      cacheTtlSecs: 0, // Disable fetcher caching
    });
    // ...
  },
});

Using a now parameter achieves the same result, since the URL is now unique and therefore not loaded from the cache. You can read all about caching in the SDK here:

P.S. - Congrats on the Pack! @Vinny_Green1 just published his own UUID Pack last week, so it’s a hot topic!

2 Likes