I would like to cash the output of a function reading data from a database and returning a panda dataframe. I keep getting the message Streamlit cannot hash an object of type <class ‘sqlalchemy.engine.base.Engine’>. I tried the suggestion shown in the error message and added the argument
allow_output_mutation=True to the
st.cache decorator but it did not help. Can this be done or is it just not possible? I am on Windows 10 and Streamlit version 0.52.0. I am currently adapting my code to read most data from a database instead of csv files so I can better prefilter the data. However, if cashing is not possible with databases I would probably try another route.
@st.cache(allow_output_mutation=True) def get_data_Collection_id(criteria): global sql_engine query = "Select * from v_data_collections" if criteria > '': query += ' where ' + criteria result = pd.read_sql_query(query, sql_engine) return result