Setting cache TTL

I think I may have tried to be a bit too clever.

I have a streamlit page which displays data retrieved from a xls file at a fixed URL.

I have cached the function which retrieves this data with the standard st.cache decorator. The data is updated every week (at 6pm on Thursdays) and I previously used to manually reset the cache when new data was available with the R key.

My streamlit server is on Google cloud, so I am a remote visitor, and after updating my streamline installation this cache reset function is no longer available to visitors.

Fine - sensible and safe. I should really be setting a programmatic cache control anyway.

So, I calculated the number of seconds until the update is due, and when calling the data function the cache ttl is now set to this value.

And now I am confused. I am calling a cached function but with a variable TTL each time. What will happen? Is the TTL updated each time I call it? Is it only set on a cache miss? Should I be doing something else entirely?

I can obviously try it and see, but it’s tedious to wait a whole week to check every change…

All advice gratefully received.

I am now suspicious that varying the ttl each time invalidates the hash and so triggers a cache miss.

However, it turns out that streamlit is so fast that I didn’t realise the cache was missing!

I’ll instrument it properly, just out of interest now.

1 Like

Your suspicion sounds reasonable to me. Curious what you find out.

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