Caching in Jupyterlab extension

I’ve created a jupyterlab extension using the jupyterlab/filebrowser package which helps the user to open a certain kind of files stored in a database.

Now whenever a user opens a file, a certain portion of the file data gets cached in a dictionary defined in handlers.py of my extension. Since I’ve declared it in handlers.py the lifetime of the cache is tied to the lifetime of the jupyter server. Restarting the Jupyter server will clear any data in the cache.

But if the jupyterlab server is not restarted for a long time, I fear that the cached data can hinder the performance of the extension or maybe jupyterlab too.

Can someone recommend me a solution to tackle the issue? Or is there a way to flush the cached dict present in handlers.py, when we refresh the jupyterlab URL (which of course doesn’t restart the jupyterlab server)?