Skip to content

Instantly share code, notes, and snippets.

@cassolmc
Created August 24, 2022 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cassolmc/baa9c5837da4462f87ee410fe35d309b to your computer and use it in GitHub Desktop.
Save cassolmc/baa9c5837da4462f87ee410fe35d309b to your computer and use it in GitHub Desktop.
Flask-Caching with Azure redis
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