Server: Werkzeug/0.9.4 Python/2.7.5+ X-Cache: miss 1000 """ from httplib import BAD_REQUEST, OK from time import sleep from werkzeug.contrib.cache import FileSystemCache from flask import Flask, render_template, request from flask.ext.webcache import easy_setup, modifiers app = Flask(__name__) werkzeug_cache = FileSystemCache('/tmp/.sleepycalc') easy_setup(app, werkzeug_cache) PLAINTEXT = (('Content-Type', 'text/plain'),) @app.route("/") def index(): return render_template("index.html") @app.route("/addition") @modifiers.cache_for(seconds=30) def addition(): try: term1, term2 = int(request.args['term1']), int(request.args['term2']) except (KeyError, ValueError): return 'term1/term2 expected as integer query arguments', BAD_REQUEST, PLAINTEXT result = term1 + term2
# -*- coding: utf-8 -*- import os from flask import Flask, send_from_directory from werkzeug.contrib.cache import FileSystemCache from flask.ext.webcache import easy_setup, modifiers application = Flask(__name__) route = application.route application.debug = True werkzeug_cache = FileSystemCache('/tmp/.sleepycalc') easy_setup(application, werkzeug_cache) @route('/') def index(): return "Hello World" @route('/curtime') def curtime(): return '{"time": "2015-06-22 12:00"}' @route('/badges/<string:repo>/<string:branch>/<string:badge>.svg') @modifiers.cache_for(seconds=0) def send_badges(repo, branch, badge): base_path = os.path.join(os.getcwd(), 'static', 'badges', repo, branch) print base_path
X-Cache: miss 1000 """ from __future__ import division, unicode_literals from six.moves.http_client import BAD_REQUEST, OK from time import sleep from werkzeug.contrib.cache import FileSystemCache from flask import Flask, render_template, request from flask.ext.webcache import easy_setup, modifiers app = Flask(__name__) werkzeug_cache = FileSystemCache('/tmp/.sleepycalc') easy_setup(app, werkzeug_cache) PLAINTEXT = (('Content-Type', 'text/plain'), ) @app.route("/") def index(): return render_template("index.html") @app.route("/addition") @modifiers.cache_for(seconds=30) def addition(): try: term1, term2 = int(request.args['term1']), int(request.args['term2']) except (KeyError, ValueError):