Created
August 24, 2022 19:40
-
-
Save cassolmc/baa9c5837da4462f87ee410fe35d309b to your computer and use it in GitHub Desktop.
Flask-Caching with Azure redis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
from flask import Flask, jsonify | |
from flask_caching import Cache | |
app = Flask(__name__) | |
cache = Cache(app, config={ | |
"DEBUG": True, | |
'CACHE_TYPE': 'RedisCache', | |
'CACHE_REDIS_HOST': '', # Azure reris URL | |
'CACHE_REDIS_PORT': '', # Azure redis port | |
'CACHE_REDIS_PASSWORD': '', # Azure redis access key | |
'CACHE_OPTIONS': { | |
'ssl': True | |
} | |
}) | |
@app.route("/time") | |
@cache.cached(timeout=10) | |
def route1(): | |
now = datetime.datetime.now() | |
return jsonify(now=now) | |
if __name__ == '__main__': | |
app.run(host='0.0.0.0', port=5000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment