Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,18 +274,31 @@ def cs_body():

col3.subheader('Optimize performance')
col3.code('''
@st.cache
>>> @st.cache
@st.experimental_memo
# Function decorator to memoize function executions
>>> @st.experimental_memo
... def fetch_and_clean_data(url):
... # Mutate data at url
... # Fetch data from URL, clean it up.
... return data
>>> # Executes d1 as first time
>>> d1 = fetch_and_clean_data(ref1)
>>> d1 = fetch_and_clean_data(DATA_URL_1)
>>> # Does not execute d1; returns cached value, d1==d2
>>> d2 = fetch_and_clean_data(ref1)
>>> d2 = fetch_and_clean_data(DATA_URL_1)
>>> # Different arg, so function d1 executes
>>> d3 = fetch_and_clean_data(ref2)

>>> d3 = fetch_and_clean_data(DATA_URL_2)
@st.experimental_singleton
# Each singleton is shared across all users connected
>>> @st.experimental_singleton
... def get_database_session(url):
... # Create a database session object
... return session
>>> # Executes s1 as first time
>>> s1 = get_database_session(SESSION_URL_1)
>>> # Does not execute; returns cached value, s1==s2
>>> s2 = get_database_session(SESSION_URL_1)
>>> # Different arg, so function d1 executes
>>> s3 = get_database_session(SESSION_URL_2)
>>> # This is a different URL, so the function executes.
''')

col3.subheader('Other key parts of the API')
Expand Down