Skip to content
Snippets Groups Projects
Commit db38cea0 authored by Anton Sarukhanov's avatar Anton Sarukhanov
Browse files

Cache AJAX responses for 5 seconds

parent e3ca56bb
No related branches found
No related tags found
No related merge requests found
import os
from flask import Flask, jsonify, make_response, render_template, request, abort
from flask.ext.bower import Bower
from flask.ext.cachecontrol import FlaskCacheControl, cache_for
from jinja2.exceptions import TemplateNotFound
from sqlalchemy.orm import joinedload
from models import db, Agency
......@@ -20,6 +21,9 @@ db.init_app(app)
Bower(app)
cache_control = FlaskCacheControl()
cache_control.init_app(app)
# Flask Web Routes
@app.route('/')
def map():
......@@ -43,6 +47,7 @@ def map_embed(mode):
return render_template('predictions.html', agency=agency, config=app.config, embed=True)
@app.route('/ajax')
@cache_for(seconds=5)
def ajax():
""" Handle all async requests (from JS). """
query = request.args.get('query')
......
Flask==0.10.1
Flask-Bower==1.2.1
Flask-CacheControl==0.1.2
Flask-Celery-Helper==1.1.0
Flask-Migrate==1.6.0
Flask-SQLAlchemy==2.1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment