Cache connection to Firestore?

I’m creating a dashboard with Streamlit where I’m currently connecting to my data warehouse (BigQuery) and the docs show how to cache the connection to BigQuery. However, I can’t seem to find the same option for Firestore? Is this possible?

1 Like

Hi @digitalghost-dev,

Thanks for posting!

You can use st.cache_resource to cache the function that creates the connection to Firestore.

1 Like

Thank you for responding, Tony.

Does this function look correct to you?

def firestore_connection():
	if not firebase_admin._apps:

	return firestore.Client(credentials=credentials)

The documentation for connecting to Firestore just links to a blog post but I don’t see @st.cache_resource being used at all in the post so not sure if I am using it correctly.

1 Like

Yes, your function looks correct. You can control the caching behavior with parameters like ttl (time-to-live) and max_entries. If your Firestore client doesn’t need to refresh often, you could set a longer ttl.

Are you referencing this blog? If yes, there are a good number of releases that have happened after this blog was published in 2021 that would make some parts of the blog outdated.

Please let me know if you run into any other issues.

Yes! That is the blog I’m referring to. Are there plans to create a doc like the other connections listed under Knowledge Base > Tutorials > Connect to data sources ?

Thanks for the check and listing out the parameters.

1 Like

Am glad you found the solution. Yes, the goal is to eventually populate the tutorials with more data sources. You can actually build and contribute more connections. We have st.connection as a new easier way to connect to data sources. Check out this example in our docs.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.