Ashley Felton  committed f3f3b77

Add simple caching of views via Flask-Cache.

  • Participants
  • Parent commits 334d2a9

Comments (0)

Files changed (3)

File requirements.txt


File temper/

 from flask import Flask
+from flaskext.cache import Cache
 # Configure application
-DEBUG = True
+DEBUG = False
+CACHE_TYPE = 'simple'
+CACHE_DEFAULT_TIMEOUT = 60 * 5  # Cache for 5 minutes by default.
 app = Flask(__name__)
+cache = Cache(app)
 import temper.views

File temper/

 import json
 from flask import request, render_template
-from temper import app, utils
+from temper import app, utils, cache
 from datetime import datetime
 def temps_week():
     # Read up to 7 days-worth of log files.
     temps_li = utils.read_logs(n=7)
 def temps_all():
     # Read all log files.
     temps_li = utils.read_logs()
+@cache.memoize(timeout=60 * 60 * 24)  # Cache 24h
 def log_date(year, month, day):
     # Read the log file for the specifed date.
     log_date = '{0}-{1}-{2}'.format(year, month, day)