python
   @st.cache(allow_output_mutation=True)
   def my_cached_func(...):
      ...
For examples, see Advanced caching.
If your function returns multiple objects and you only want to allow a subset of them to mutate between runs, you can do that with the hash_funcs option.
If Streamlit is incorrectly hashing the cached object, you can override this by using hash_funcs. For example, if your function returns an object of type FooType then you could write:
python
   @st.cache(hash_funcs={FooType: hash_func_for_foo_type})
   def my_cached_func(...):
      ...
For more information, see Optimize performance with st.cache.
By the way, the scenario above is fairly unlikely — unless FooType does something particularly tricky internally. This is the case with some SpaCY objects, which can automatically mutate behind the scenes for better performance, while keeping their semantics constant. That means Streamlit will correctly detect a mutation in the object's internal structure, even though semantically that mutation makes no difference.
