# Dash Caching problem (duckdb IOException, conflicting lock, PandasAI)

**URL:** <https://community.plotly.com/t/dash-caching-problem-duckdb-ioexception-conflicting-lock-pandasai/84414>\
**Category:** Dash Python\
**Created:** [May 11, 2024, 10:24am UTC](https://community.plotly.com/t/dash-caching-problem-duckdb-ioexception-conflicting-lock-pandasai/84414 "2024-05-11T10:24:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DaGloom](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@DaGloom](https://community.plotly.com/u/DaGloom)\
**Post date:** [May 11, 2024, 10:24am UTC](https://community.plotly.com/t/dash-caching-problem-duckdb-ioexception-conflicting-lock-pandasai/84414/1 "2024-05-11T10:24:34Z")

</div>

Hey,

I was playing around with PandasAI and am facing a caching problem:

When I’m using the following code (what is just a code copy from [here](https://dash.plotly.com/minimal-app) and [here](https://www.kdnuggets.com/utilizing-pandas-ai-for-data-analysis):

```auto
from dash import Dash, html, dcc, callback, Output, Input
import plotly.express as px
import pandas as pd

from pandasai.llm import OpenAI
llm = OpenAI(api_token="put-in-your-api-token-here")

import seaborn as sns
from pandasai import SmartDataframe

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/gapminder_unfiltered.csv')

app = Dash( __name__ )

app.layout = html.Div([
    html.H1(children='Title of Dash App', style={'textAlign':'center'}),
    dcc.Dropdown(df.country.unique(), 'Canada', id='dropdown-selection'),
    dcc.Graph(id='graph-content')
])

data = sns.load_dataset('titanic')
df = SmartDataframe(data, config={'llm': llm})

response = df.chat("""Return the survived class in percentage""")

print(response)

@callback(
    Output('graph-content', 'figure'),
    Input('dropdown-selection', 'value')
)
def update_graph(value):
    dff = df[df.country==value]
    return px.line(dff, x='year', y='pop')

if __name__ == ' __main__':
    app.run(debug=True)

```

The Dash app is crashing because of a caching error:

```auto
duckdb.duckdb.IOException: IO Error: Could not set lock on file "/Users/.../dash_app/cache/cache_db_0.9.db": Conflicting lock is held in /Library/Frameworks/Python.framework/Versions/3.12/Resources/Python.app/Contents/MacOS/Python (PID 31194) by user .... See also https://duckdb.org/docs/connect/concurrency

```

Well, I tried already to downgrade Dash, PandasAI or even DuckDB, but found no solution.

Maybe you have a better idea to solve that?

Thank you again and have a nice weekend 🙂

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [May 15, 2024, 3:57pm UTC](https://community.plotly.com/t/dash-caching-problem-duckdb-ioexception-conflicting-lock-pandasai/84414/2 "2024-05-15T15:57:25Z")

</div>

Hello @DaGloom,

I’d make sure that you are only running the function once, and maybe try not reusing the same variable?

Typically, I think dash has a preflight to make sure that all layouts and things run, especially with `debug=True`, this might be what is causing your issue.

---

<div class="post-metadata">

**Author:** ![emptynonsens](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/emptynonsens/32/31125_2.png) [@emptynonsens](https://community.plotly.com/u/emptynonsens)\
**Post date:** [June 3, 2024, 8:51am UTC](https://community.plotly.com/t/dash-caching-problem-duckdb-ioexception-conflicting-lock-pandasai/84414/3 "2024-06-03T08:51:06Z")

</div>

Hello, I would suggest to change config to omit cache.db creation. I usually use setting like this:

```auto
    config = {"save_charts":True,
              "save_charts_path":full_path(if want to use your asset_foler/...),
              "conversational":True,
              "enable_cache": False,
              "llm": llm}

```

Another thing you can try, is clearing cache via clear\_cache method:

```auto
from pandasai import clear_cache

def function():
   your stuff ...
   clear_cache()
   return your stuff

```
