From df9b8fa3be094c2d08ac20ead4ca16bcd76d5b61 Mon Sep 17 00:00:00 2001
From: Anton Sarukhanov <code@ant.sr>
Date: Mon, 6 Jan 2020 22:04:18 -0500
Subject: [PATCH] Add caching.

---
 mypy.ini          | 3 +++
 requirements.txt  | 1 +
 whatformat/app.py | 4 ++++
 3 files changed, 8 insertions(+)

diff --git a/mypy.ini b/mypy.ini
index 132059d..9c56abd 100644
--- a/mypy.ini
+++ b/mypy.ini
@@ -1,2 +1,5 @@
 [mypy]
 files = whatformat/**/*.py
+
+[mypy-flask_caching.*]
+ignore_missing_imports = True
diff --git a/requirements.txt b/requirements.txt
index 230e7b2..4352144 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,2 +1,3 @@
 python-dateutil==2.8.1
 Flask==1.1.1
+Flask-Caching==1.8.0
diff --git a/whatformat/app.py b/whatformat/app.py
index 042a9e0..c544cbd 100644
--- a/whatformat/app.py
+++ b/whatformat/app.py
@@ -1,13 +1,16 @@
 """Flask app for What Format."""
 
 from flask import Flask, jsonify, render_template, request
+from flask_caching import Cache
 from whatformat.util import whatdateformat
 
 # pylint: disable=invalid-name ; These variables are standard for Flask.
 app = Flask(__name__)
+cache = Cache(app, config={'CACHE_TYPE': 'simple'})
 
 
 @app.route('/')
+@cache.cached(query_string=True)
 def landing():
     """Render the homepage."""
     date_string = request.args.get('date')
@@ -15,6 +18,7 @@ def landing():
 
 
 @app.route('/date')
+@cache.cached(query_string=True)
 def date():
     """Return date format strings matching date_string."""
     date_string = request.args.get('date')
-- 
GitLab