Can persistence be used to clear cached memory from previous user sessions?

I can really use some general direction on this issue if you can help and have the time.

I have written probably too much, because I spent several hours looking for solutions.

To spare you time and inconvenience, I have bolded the essential questions.

To start, my app receives a culinary recipe as a block of text and returns a nutritional profile. It is a multi-page app written in Python and Dash only, and I have invested nine months in its development to date.

As I finalize the project, I came to realize that it retains the data and the results from the previous recipe for too long. In other words, it returns the results of the previous recipe if you try to analyze a new recipe too soon.

That is a big problem. Big, big problem.

1. Is this a Dash issue or a problem Dash can solve?

I successfully introduced user sessions, thanks to Adam’s video; but that does not solve the problem. I sought answers in the persistence, and tried to comply with documentation. But that does not help to clear memory after a session. I also received some conflicting error messages.

For example, the Accordion component accepts persistence, persistence_type, persisted_props as arguments, but I receive a “TypeError: string indices must be integers” when I tried to use them in the manner shown below.

I also thought Dash would accept the persistence arguments in the RadioItems and charts, but they were rejected as well. This code below produces the error message above. It also rejected them when used them in the Accordion items.

What am I doing wrong here?

layout = html.Div(
        html.H5("Welcome to Ingredible's Nutrition Assistant"),
        dbc.Accordion( persistence=True, persistence_type='session', persisted_props='value'
                dbc.AccordionItem( # Step 1: Paste your recipe here.

I guess the real question is…Can Dash and/or persistence be used to clear cached memory from previous user sessions? if not, how should I approach the problem?

3. Finally, should I stop looking to Dash for a solution, and stick to Python? Clearing lists after each session and using gc.collect to solve the problem? Has anyone encountered these obstacles and can you point me in the right direction? Unfortunately, the video tutorials on YouTube focused on how gc.collect works and not on how to use it.

I am distressed about this one, but it has to be a common problem. I need to know how to clear any cached information preferably, immediately after the code produces a report.

Where should I look for solutions?

I thank you for any sincere feedback.


Hello @robertpfaff,

I found a way to clear the persistence storage directly via a clientside_callback:

    """function () {
        const keys = Object.keys(localStorage)
        for (let key of keys) {
            if (String(key).includes('_dash_persistence')) {
        return ''
    Output('persistenceClear','children'), ### placeholder for clearing
    ##Inputs to reset