Important
This is an experimental feature. Experimental features and their APIs may change or be removed at any time. To learn more, click here.
Deprecation notice
st.experimental_singleton.clear
was deprecated in version 1.18.0. Use st.cache_resource.clear
instead. Learn more in Caching.
Clear all cache_resource caches.
Function signature[source] | |
---|---|
st.experimental_singleton.clear() |
Example
In the example below, pressing the "Clear All" button will clear all singleton caches. i.e. Clears cached singleton objects from all functions decorated with @st.experimental_singleton
.
import streamlit as st
from transformers import BertModel
@st.experimental_singleton
def get_database_session(url):
# Create a database session object that points to the URL.
return session
@st.experimental_singleton
def get_model(model_type):
# Create a model of the specified type.
return BertModel.from_pretrained(model_type)
if st.button("Clear All"):
# Clears all singleton caches:
st.experimental_singleton.clear()