Browse Source

cache home view

pull/4/head
欧醚 3 years ago
parent
commit
eb73d39ba2
2 changed files with 5 additions and 1 deletions
  1. +4
    -0
      app.py
  2. +1
    -1
      requirements.txt

+ 4
- 0
app.py View File

@ -6,6 +6,7 @@ from flask import (Flask, request, render_template, send_from_directory, abort,
from flask_sqlalchemy import SQLAlchemy
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address
from flask_caching import Cache
from mastodon import Mastodon
import random
from config import C
@ -29,6 +30,8 @@ app = Flask(__name__)
app.config.from_object('config.C')
app.secret_key = C.session_key
cache = Cache(config={'CACHE_TYPE': 'SimpleCache'})
cache.init_app(app)
MAST_LOGIN_URL = Mastodon(api_base_url=C.mast_base_uri).auth_request_url(
client_id = C.mast_client_id,
@ -203,6 +206,7 @@ def logout():
@bp.route('/')
@cache.cached(timeout=10)
def home():
stories = Story.query.order_by(Story.total_like_num.desc()).all()
return render_template('home.html', **locals())

+ 1
- 1
requirements.txt View File

@ -1,5 +1,5 @@
Flask~=2.0.2
Flask_Limiter~=1.4
Flask_SQLAlchemy~=2.5.1
mastodon~=0.0.1
Mastodon.py~=1.5.1
Flask-Caching

Loading…
Cancel
Save