Caching in Packs

Can anyone (perhaps a Codan) shed some light on how formula output is cached in Packs?

Aggressive caching makes sense in many situations

For example, in the IMDB Pack I’ve built, I have a formula (and column type) that takes a movie name and returns a bunch of info about the movie, like a poster image. This info is very unlikely to change, so I’d like Coda to avoid hitting the API unless the formula input changes. As far as I can tell so far, this is the default behaviour :+1: (in fact, it even seems to cache responses from an earlier build of the Pack… which I’m not so sure is a good idea - maybe worth thinking about that one)

But…

In my Currency Conversion pack, one of the formulas pulls the latest available rate for a currency pair. Is there some way to configure periodic re-checks at a certain interval? Some kind of “time to live” value? Or thoughts on how to structure a way for users to manually trigger an update?

(As a bonus, it would be great for me to be able to ask Coda to cache certain API responses across users - Forrest Gump has the same poster no matter whose API key is asking. I can see how this would be a bit of a security foot-gun waiting to go off though…)

1 Like

This is a fascinating realm that certainly needs some ideas and guideposts. In data science, caching is critical, and we can see some cases where it’s done quite seamlessly such as in Python (see Streamlit st.cache()). But they are also experimenting with more advanced techniques.

1 Like

There are two levels of caching in Packs:

  1. External data pulled by the Fetcher is cached. You can read more about that here.
  2. Formula results are cached. This can be adjusted / disabled by setting the cacheTtlSecs property of the formula definition.

As to your bonus question, this isn’t possible today. We don’t support explicit caching of data at the moment.

4 Likes

Thanks Eric! I’m continually impressed with how robust Pack Studio is. For a lot of the gotchas I come up with as I go, I’ve been finding well-reasoned design choices like this.

I guess you’ve had some time to think about this kind of thing with your internal packs for years, but still :slight_smile:

1 Like

Also note that even after a cache invocation expires, the formula won’t necessarily be re-invoked in the doc, if none of its dependencies have changed. To force a formula to get re-invoked, you could consider making it take a volatile parameter, like Today(). When the date changes, the formula will get re-invoked.

2 Likes

Oh @Eric_Koleda what are your thoughts on the fact that formula results seem to be cached even when a new version of the Pack is built? Is this the expected behaviour?

My worry is if I needed to push an update to a Pack to correct a bug or error, existing rows wouldn’t receive the corrections.

A new version of the Pack should invalidate the cache, but by default it won’t cause the formulas to recalculate. You can manually force a recalculation by visiting Explore > Packs & import > {Pack Name} > Settings > ⭮ (“Refresh Now”). To do this automatically when a new Pack version is loaded, toggle on the Auto-refresh when version changes toggle on the same pane.

1 Like

Thanks Eric, that matches my experience

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.