Adding flask_cache
This commit is contained in:
parent
fc9c721d96
commit
ae1b44d85a
5 changed files with 19 additions and 4 deletions
|
@ -12,6 +12,7 @@ nose==1.3.7
|
|||
pbr==2.0.0
|
||||
pycodestyle==2.3.1
|
||||
pyflakes==1.5.0
|
||||
pylibmc==1.5.2
|
||||
PyMySQL==0.7.11
|
||||
six==1.10.0
|
||||
SQLAlchemy==1.1.9
|
||||
|
|
|
@ -23,6 +23,7 @@ except ImportError:
|
|||
from src.models import db
|
||||
from src.views.errors import error_pages
|
||||
from src.views.scoreboard import scoreboard
|
||||
from src.resources.utilities import cache
|
||||
import sys
|
||||
import flask_bootstrap
|
||||
import flask
|
||||
|
@ -33,6 +34,7 @@ def create_app(config_name):
|
|||
app.config.from_object(config[config_name])
|
||||
|
||||
db.init_app(app)
|
||||
cache.init_app(app)
|
||||
config[config_name].init_app(app)
|
||||
flask_bootstrap.Bootstrap(app)
|
||||
app.register_blueprint(scoreboard)
|
||||
|
|
|
@ -30,11 +30,14 @@ class Config:
|
|||
SQLALCHEMY_COMMIT_ON_TEARDOWN = True
|
||||
DEBUG = True
|
||||
# Server Settings
|
||||
SERVER_NAME = "localhost:5000" # If not set correctly will generate lots of 404's
|
||||
ADMIN_EMAIL = "admin@localhost.com"
|
||||
ADMIN_NAME = "WebMaster"
|
||||
APP_IP = "0.0.0.0"
|
||||
SERVER_NAME = "localhost:5000"
|
||||
ADMIN_EMAIL = "metonymy@fedoraproject.com"
|
||||
ADMIN_NAME = "Metonymy"
|
||||
APP_IP = "localhost"
|
||||
APP_PORT = 5000
|
||||
CACHE_TYPE = "memcached"
|
||||
CACHE_DEFAULT_TIMEOUT = 60
|
||||
CACHE_KEY_PREFIX = "benchmark_scoreboard"
|
||||
# Pagination
|
||||
MAX_RESULTS_PER_PAGE = 50
|
||||
MAX_PAGES = 2
|
||||
|
@ -46,6 +49,7 @@ class Config:
|
|||
|
||||
class DevelopmentConfig(Config):
|
||||
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'database.sqlite')
|
||||
CACHE_TYPE = "simple"
|
||||
|
||||
@staticmethod
|
||||
def init_app(app):
|
||||
|
@ -73,6 +77,7 @@ class ProductionConfig(Config):
|
|||
|
||||
class TestingConfig(Config):
|
||||
MAX_RESULTS_PER_PAGE = 1
|
||||
CACHE_TYPE = "simple"
|
||||
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'test_database.sqlite')
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
along with scoreboard-benchmark . If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
from flask_cache import Cache
|
||||
|
||||
cache = Cache()
|
||||
|
||||
|
||||
def to_zero_count(page_no):
|
||||
"""
|
||||
|
|
|
@ -24,6 +24,7 @@ import flask
|
|||
scoreboard = flask.Blueprint('scoreboard', __name__, template_folder='templates')
|
||||
|
||||
|
||||
@utilities.cache.cached(timeout=60*10)
|
||||
@scoreboard.route("/upload")
|
||||
def upload():
|
||||
"""
|
||||
|
@ -72,6 +73,7 @@ def result_post():
|
|||
return flask.jsonify({'success': True, 'location': location}), 201, {'location': location}
|
||||
|
||||
|
||||
@utilities.cache.cached(timeout=60*5)
|
||||
@scoreboard.route("/result/<id>", methods=['GET'])
|
||||
def result(id):
|
||||
"""
|
||||
|
@ -85,6 +87,7 @@ def result(id):
|
|||
flask.abort(404)
|
||||
|
||||
|
||||
@utilities.cache.cached(timeout=60)
|
||||
@scoreboard.route("/", methods=['GET', 'POST'])
|
||||
def index():
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue