adds flask caching

This commit is contained in:
2026-01-24 19:04:09 -05:00
parent 8047d07b86
commit 97ca92b945
2 changed files with 12 additions and 2 deletions

13
app.py
View File

@@ -2,9 +2,19 @@ from flask import Flask, render_template, jsonify, request
from utils.weather import get_today_snowfall
from utils.geocode import get_city_name
from config import MAX_SNOW_INCHES
from flask_caching import Cache
app = Flask(__name__)
# Cache config: 10-minute default timeout
cache = Cache(app, config={"CACHE_TYPE": "SimpleCache", "CACHE_DEFAULT_TIMEOUT": 600})
@cache.memoize(600) # cache each request for 10 minutes
def get_snowfall_for_location(lat, lon):
inches, snowing, tz_name = get_today_snowfall(lat, lon)
city_name = get_city_name(lat, lon)
return inches, snowing, tz_name, city_name
@app.route("/")
def index():
return render_template("index.html")
@@ -16,8 +26,7 @@ def snowfall_api():
if lat is None or lon is None:
return jsonify({"error": "Missing lat/lon"}), 400
inches, snowing, tz_name = get_today_snowfall(lat, lon)
city_name = get_city_name(lat, lon)
inches, snowing, tz_name, city_name = get_snowfall_for_location(lat, lon)
from datetime import datetime
import pytz