Skip to content

Instantly share code, notes, and snippets.

@ruanbekker
Created May 12, 2018 20:55
Show Gist options
  • Save ruanbekker/9c61f8d682e795f7c4ce9c627d92f0e4 to your computer and use it in GitHub Desktop.
Save ruanbekker/9c61f8d682e795f7c4ce9c627d92f0e4 to your computer and use it in GitHub Desktop.
Flask-Cache Example with Simple Type
from flask import Flask
from flask_caching import Cache
import random
app = Flask(__name__)
cache = Cache(app, config={'CACHE_TYPE': 'simple'})
@app.route("/route1")
@cache.cached(timeout=10)
def route1():
data = str(random.randint(0,100000)) + '\n'
return data
@app.route("/route2")
@cache.cached(timeout=20)
def route2():
data = str(random.randint(0,100000)) + '\n'
return data
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8098)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment