Components as objects

I’m wondering if it would be possible to create a custom component that when instantiate can be treated as an object: so it’s possible to cache it and call methods.

For example, in a project I recently started (GitHub - lfoppiano/streamlit-pdf-viewer: Streamlit PDF viewer), we are trying to build a component to render PDFs and show annotations on it. Ideally, we would like to cache the object after the pdf is loaded, and then, for example, if we want to update the annotations or remove them, to call a method without reloading the whole thing.

You can see a showcase here: https://structure-vision.streamlit.app/

Many thanks for considering my question.