🚀 Gen 5 of the leading AI app deployment platform launches October 6. Click for the livestream.

Show and Tell - Server Side Caching

Your advice from another thread brought me here.

Very interested in trying this out. Looking at the MRE, it seems like we should replace Dash, Output, and Input imports that were originally from dash, with dash_extensions.enrich.

Just curious why this would be the arrangement, wouldn’t it have been easier to import onlyServersideOutput from dash_extensions.enrich alone, while importing the rest from the original dash library.

Additionally, when file_system_store is created as a folder, wouldn’t the data still eventually need to be transmitted from the server to the client? How are you able to achieve such speed?

I am modifying the behavior of the objects that you mention, that is why they must be imported differently.

No, the data stays on the server. That is essentially how the performance improvement is achieved.

Okay, and in the MRE - each time the button is clicked, the data in file_system_store on the server is updated right? Perhaps I’d look to use a dcc.Interval to return the latest data into ServersideOutput, from which I can use as inputs to my charts.

Is it as simple as I’m making it out to be?

Yes, that sounds about right. That being said, for your use case it seems to me that a scheduled background task (running on the server at regular intervals) that updates a server cache might be a more proper design.

I assume you’re recommending so, so that the data can be updated even though nobody is visiting the site, and the expensive querying step will not hinder the first visitor, right?

Would I look up on flask caching sql query for more information on the separately scheduled background task?

Yes, exactly. There are tons of tools that could be used. A simple solution could be a Python script that fetches the data and writes them to a file invoked by a scheduler, e.g. Cron or a Python one.

1 Like

does ServersideOutput work with the callbacks on dash 2.0’s all-in-one components ?

I haven’t tested it, but i believe so. As I understand, they are just “normal” pattern matching callbacks. However it does not work with the new decorator that omits the app object.

Thank you for the reply. The new @callback is what I was referring to and your reply confirms my observation.

Any plan to make it work for the new @callback? or is it even possible to make it work when an dash AIO component has no knowledge of app object and in the meantime flask_caching is coupled with an app object?

I believe it should be possible, I already have a few ideas on how to address it.