Caching Database queries

Hey All,

I’ve been trying to set up a cache in my dash app and keep seeing KeyError: 'cache'
The way that I set up either caching is exactly as in https://dash.plot.ly/performance
Can anyone advise?

Additionally, if i try to set up redis (which is running correctly) as done here: https://stackoverflow.com/questions/24589123/how-to-cache-sql-alchemy-calls-with-flask-cache-and-redis
I get this error AttributeError: 'Dash' object has no attribute 'jinja_env'

My app takes user input and creates a MySQL query and executes it. The custom query is generated via a dropdown input form the user and I was hoping to improve performance by incorporating caching.

I had similar issues and got it to work this way, you?

| project
| -> server.py
| -> app.py

server.py:

from flask import Flask
from flask_caching import Cache
import redis
server = flask(name)

cache = Cache(server, config={
‘CACHE_TYPE’: ‘redis’,
‘CACHE_REDIS_URL’: settings.redis_address + ‘:’ + settings.redis_port,
})
redis_server = redis.Redis(host=‘address’, port=‘port’)

app.py:

import dash
from server import server

app = dash.Dash(name, server)

Now from everywhere else I just use “from server import cache, redis_server” to utilize these.

If my code is wrong ord does not work for you I am very interested in feedback.

Best
Theis