From fd0f10e625dca6481aab0cb0dfe3857e380d470b Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Fri, 25 Aug 2017 23:27:12 -0400 Subject: [PATCH] add caching Signed-off-by: Kenneth Reitz --- Pipfile | 1 + scraper.py | 2 ++ server.py | 8 ++++---- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Pipfile b/Pipfile index 361c2a1..ea10c69 100644 --- a/Pipfile +++ b/Pipfile @@ -14,3 +14,4 @@ html5lib = "*" bs4 = "*" requests = "*" simplejson = "*" +flask-cache = "*" diff --git a/scraper.py b/scraper.py index c758d6e..b6854f1 100644 --- a/scraper.py +++ b/scraper.py @@ -46,9 +46,11 @@ class MWT(object): return func + def convert_to_decimal(f): return Decimal("{0:.8f}".format(f)) + class Coin(): """A Coin, unlike Mario's.""" diff --git a/server.py b/server.py index 0e6f58d..0a1b11a 100644 --- a/server.py +++ b/server.py @@ -4,6 +4,7 @@ from scraper import get_coins, get_coin, Coin from wallets import wallets from flask import Flask, jsonify, render_template, request +from flask.ext.cache import Cache from flask_sslify import SSLify import maya @@ -17,11 +18,13 @@ pro_db = records.Database(os.environ['HEROKU_POSTGRESQL_TEAL_URL']) app = Flask(__name__) -app.debug = True + sslify = SSLify(app) +cache = Cache(app ,config={'CACHE_TYPE': 'simple'}) @app.route('/') +@cache.cached(timeout=60) def hello(): lbc = get_coin('lbc') @@ -80,9 +83,6 @@ def get_history(coin): else: rows = db.query(q, coin=c.name) - - - return jsonify(history=[ { 'value': r.value,