From 19655b24dfb6f0c89448404e7b962ea82ca0c139 Mon Sep 17 00:00:00 2001 From: Yax <1949284+kianby@users.noreply.github.com> Date: Sat, 8 Jul 2017 18:53:49 +0200 Subject: [PATCH] flask cache --- app/__init__.py | 2 ++ app/controllers/api.py | 2 ++ requirements.txt | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/__init__.py b/app/__init__.py index d7562aa..289b569 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,3 +1,5 @@ from flask import Flask +from flask.ext.cache import Cache app = Flask(__name__) +cache = Cache(app, config={'CACHE_TYPE': 'simple'}) diff --git a/app/controllers/api.py b/app/controllers/api.py index 1879b6b..0e6e216 100644 --- a/app/controllers/api.py +++ b/app/controllers/api.py @@ -5,6 +5,7 @@ import logging import config from flask import request, jsonify, abort from app import app +from app import cache from app.models.site import Site from app.models.comment import Comment from app.helpers.hashing import md5 @@ -45,6 +46,7 @@ def query_comments(): return r +@cache.cached(timeout=300) @app.route("/comments/count", methods=['GET']) def get_comments_count(): try: diff --git a/requirements.txt b/requirements.txt index 4b7c647..02673a5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ clize==2.4 Flask==0.10.1 +Flask-Cache==0.13.1 Flask-Cors==2.0.1 itsdangerous==0.24 Jinja2==2.7.3 @@ -11,4 +12,3 @@ PyRSS2Gen==1.1 requests==2.7.0 six==1.9.0 Werkzeug==0.10.4 -wheel==0.24.0