Skip to content

Commit

Permalink
Update example in button guide (#1214)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dmatthews authored Dec 24, 2024
1 parent 2082409 commit a1f5864
Showing 1 changed file with 1 addition and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,8 @@ if 'processed' not in st.session_state:
if st.button('Process'):
result = expensive_process(option, add)
st.session_state.processed[option] = result

if option in st.session_state.processed:
st.write(f'Option {option} processed with add {add}')
st.write(st.session_state.processed[option][0])
result[0]
```

Astute observers may think, "This feels a little like caching." We are only saving results relative to one parameter, but the pattern could easily be expanded to save results relative to both parameters. In that sense, yes, it has some similarities to caching, but also some important differences. When you save results in `st.session_state`, the results are only available to the current user in their current session. If you use [`st.cache_data`](/develop/api-reference/caching-and-state/st.cache_data) instead, the results are available to all users across all sessions. Furthermore, if you want to update a saved result, you have to clear all saved results for that function to do so.
Expand Down

0 comments on commit a1f5864

Please sign in to comment.