CHRD
CHRD

Reputation: 1957

Plotly dash server side caching

I'm using server side caching in my dash application and I've followed example 4 in the documentation. I'm using this to query and process the "global" data, this prepared dataset is then shared between the different components in the application.

This works fine; the data loads when I load or refresh the application.

But the data also reloads when I've left the application for a couple of minutes and come back (e.g. visiting another tab in the browser without closing the app). So what I'm confused around is how these sessions work and why they seem to expire so quickly. What is the approach to control this? E.g. via increasing allowed idle time or strictly renewing the session on page load/refresh.

Upvotes: 4

Views: 12355

Answers (1)

emher
emher

Reputation: 6014

The memoized data is refreshed when one of three things happen,

  1. The value(s) of the input argument(s) change
  2. The cache has expired
  3. The cache has been cleared

In the example in your link, a new uuid is generated on each page load. This id is passed as an argument to the memoized function, and the data will thus be refreshed on page load due to (1).

If more than a predefined timeout has passed (default value is 300 seconds)), the data will be refreshed as per (2). That's probably why you're experiencing that "the data also reloads when I've left the application for a couple of minutes and come back". You can adjust timeout to your needs via the CACHE_DEFAULT_TIMEOUT parameter of the Cache object or via the timeout keyword of the memoize decorator.

In addition, the cache will be refreshed if the data cannot be found (3). Besides manual deletion, this can happen if the cache runs out of space. Per default, 500 cache elements are kept. This number can be adjusted via the CACHE_THRESHOLD argument of the Cache object.

Upvotes: 4

Related Questions