How to hash only string input function parameters

Hi ! I’m sorry having to ask, but I seem to not really understand caching system.
I have a function quite short now, but with many pandas dataframes, SQLAlchemy objects, which make requests. It tooks only 2 strings as parameters and I would like to run it only when at least one of them changes.

The problem is that it is way too long, more than 30 seconds to hash a simple function !! I used this code to remove hashing heavy objects but nothing changes.

@st.cache(hash_funcs={sqlalchemy.orm.properties.ColumnProperty: lambda _: None,
pd.DataFrame: lambda _: None}) 

So my question is why is it so long ? There is quite nothing to hash. And by the way in production mode I don’t care about hashing the body function, it will not change (and could reach +1000 lines). So basicaly I just want to hash 2 little strings, and nothing else.
How can I do this ?

Hi @David_M, welcome to the forum :wave:

It’s not possible to hash only the function inputs at the moment, but feel free to file a feature request!

However, when hashing the body of the function we also hash the implicit inputs to the function, which could change even if the body of the function doesn’t.

30 seconds sounds very long for hashing the function, are you sure it’s not re-running the function each time?

You can verify cache misses or hits in your server logging

DEBUG   streamlit.caching: Cache miss: <function load_data at 0x120909170>
DEBUG   streamlit.caching: Cache hit: <function load_data at 0x120909170>

To be able to help you further, could you share sample code that we can copy/paste and run to reproduce your issue?

Lastly, a 1000+ line function sounds very long! Could you break that into smaller functions and cache selectively?