Strategy for caching monthly released data

Summary

The data on my app is released monthly, on a date that isn’t the same every month (sometimes the 5th, sometimes the 8th, and so on).

When the data is released I need the user to immediately have access to the new data, but at the same time, knowing the data won’t change for a whole month, I want to use “@st.cache_data” to cache the data until the next release, so that the database API requests/minute limit isn’t reached with various users using it simultaneously.

So my first question is, when I’m logged to my app and I use the “clear cache” button does it clear it just for me or for all users using the app? If for all users that would be a solution, to put an almost infinite ttl argument for cache data such as “@st.cache_data(ttl=999999999)” and clear cache manually when the new data is released.

Another option would be to reboot the app. Does rebooting the app clear the cached data for all users?

If someone can think of another strategy, it would also be greatly appreciated.

Debug info

  • Streamlit version: 1.21.0
  • Python version: 3.9
  • Using Conda? PipEnv? PyEnv? Pex? → no to all
  • OS version: Windows 10
  • Browser version: Chrome 112

[Someone please correct me if I’m wrong]

After some testing, it seems that the cache is saved server-side, not user-side, what means that each user doesn’t trigger a new query to the database, only the first user that loads the database after the cache expires does.

It also seems that when you use the “clear cache” option it clears it for all the users of the app.

I tested those using my phone and my computer simultaneously to access the app.

Seems correct to me. Streamlit has a server-client architecture. When you have the app hosted, the only thing happening on the user side is to view the dynamically generated web page. All Python logic and storage happens on the server, and yes the cache is something accessed by all sessions rather than something tied to a particular session.

1 Like

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