How to cache Flask-App-Builder views?

Question

I have a working Flask app with pretty extensive SQLite database (~100k entries). I'm struggling to bootstrap some ModelViews with Flask-App-Builder (FAB) in simplest way according to docs:

class MyModelView(ModelView):
  datamodel = SQLAInterface(MyModel)
  list_columns = ['col1', 'col2']

than enabling them like this:

appbuilder.add_view(MyModelView, 'Models')

It works fine. The problem is, every time I visit list view, it is generated from scratch - DB query, some FAB processing, template generation. And it is subjectively very slow (tens of seconds by wall clock; I'm not sure how to properly profile Flask application).

I think caching FAB views at some point may help speed up things, but I'm unsure how to go about it. For ordinary views I use Flask-Cache:

@app.route('/some_route')
@cache.cached()
def view_function():
    data = time_consuming_operation()
    return render_template('template.html', data=data)

So, question:

How one would use cache with FAB ModelViews? Is there a way to speed up work of FAB ModelViews?

Thank you!


Show source
| caching   | python   | flask   | flask-appbuilder   2017-01-07 22:01 0 Answers

Answers to How to cache Flask-App-Builder views? ( 0 )

Leave a reply to - How to cache Flask-App-Builder views?

◀ Go back