When several people open a Streamlit app, each gets a new app instance. A database connection is different: creating one for every user or browser tab is unnecessary. st.cache_resource is a decorator for keeping a resource shared across users and sessions. section 8.2.5
For a connection created with st.connection, there is no need to add the decorator yourself: Streamlit applies it internally to the returned connection. By contrast, st.cache_data is for values such as dataframes and API results. section 8.2.5
class Database:
def __init__(self):
self.conn = st.connection("haikuconn", type="sql")
The Database initializer obtains its SQL connection through st.connection, without an explicit caching decorator. section 8.2.5
