Refreshing URL and Caching responses

Hey all!

I am building a doc and the client (my wife!) is looking to feature a quick “thought of the day” or quote at the top of a certain page. I know I can do that with a table and randomize but…what if I built a pack?

I found a silly “nerd jokes” API and it will fetch a joke easily. My question is - How would I go about making it refresh the url each time it goes to fetch? I have used cacheTtlSecs and set it to zero but the formula still seems to return the same string.

Is there something I should to the GET request to refresh the URL or would you think of it a different way?

Hi @Thomas_Baucom - There are two different levels of caching in Packs: formula and network. They both are set using cacheTtlSecs, but one on the formula and the other on the fetch request.

pack.addFormula({
  name: "RandomJoke",
  // ...
  cacheTtlSecs: 0,
  execute: async function ([param], context) {
    let response = await context.fetcher.fetch({
      method: "GET",
      url: "...",
      cacheTtlSecs: 0,
    });
    // ...
  },
});

Let me know if that solves it for, and happy Pack making!

3 Likes

Hey @Eric_Koleda, it did indeed! Thanks for the response.

I also stumbled upon on the idea of randomizing a parameter in the formula and having it constantly update. This led to non-stop jokes and refreshing.

Have a great weekend everyone!

1 Like