CACHE : dcc.Store vs Redis vs Flask-Caching - Open Discussion

Hey everyone,

Would anyone being able to explain the empirical difference between dcc.Store, Flask-Caching, and Redis ? My concern being mainly saving data “on-the-fly”.

I really love how dash makes it simple to develop your App, and in order to start improving the Data Storage aspect in a light way, I was thinking about using dcc.Store.

However, I hear many good things about Redis while not so many people seem to be using it. Is it to be considered when you reach the 10 MB memory limit of dcc.Store?

For the moment, I’d consider using dcc.Store to keep the consistency of the “Dash environment”. However, i may be missing some great features with Redis. Or I may be totally wrong considering one or the other, cause they are totally different. Should we compare more dcc.store to Flask-Caching?

dcc.Store info : https://dash.plot.ly/dash-core-components/store

Many thanks in advance to you guys, for taking the time to read and reply.

Have a nice day,

Quentin

1 Like

Hey Quentin,

You have a little misconception there, so I’d try to clarify as much as I can :slight_smile:

To begin with, know that dcc.Store is a dash component, Flask-Caching is a caching library and Redis is a database. You already know what they have in common: in some way they are used to store data, but keep in mind the differences as they are huge.

When using dcc.Store, what you put there is saved in the user’s browser. This is client-side caching. This means that storing things there will have no effect for another user who is happening to use the same app at the same time. This can be useful for example for storing user-filtered results that must be shared between different callbacks of your app and you don’t want to be recalculating the filtered results over the original data.

On the other hand, there’s server-side caching. Imagine that you had an expensive method which you’d be fine just calculating once an hour, and its result must be the same for every user that accesses your app. Then it would make no sense to store that result on a dcc.Store and you should do it on some storage system on your server. You could code this system by yourself, but then there is Flask-Caching: a library which will make your life easier by giving you the minimal tools you need to implement this.

With Flask-Caching, you can then decide between different storage systems. You could cache results on your server’s filesystem (the default, I think), or you could use a more formal database. That’s when Redis and other databases comes into the equation.

So in summary, use dcc.Store when you want to store data for a specific user, then use a server-side caching system when you want to store data for all users. If you don’t want to code this system yourself, use a library like Flask-Caching. If you want to use a database for caching, you can then go and use Redis.

Hope this helped you!

13 Likes

Yeah, I think it could have not been clearer :slight_smile: . The distinction between Client’s and Server’s side made me understood.

Thanks for taking the time @Jendoliver , it is very appreciated.

1 Like