Created
August 17, 2015 03:00
-
-
Save TheWaWaR/767480a45bbc4bef0b6c to your computer and use it in GitHub Desktop.
Test flask cache concurrency.
This file contains hidden or 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
#!/usr/bin/env python | |
#coding: utf-8 | |
import sys | |
import time | |
from datetime import datetime | |
from flask import Flask | |
from flask.ext.cache import Cache | |
cache = Cache() | |
app = Flask(__name__) | |
app.config.update({ | |
'CACHE_TYPE': 'redis', | |
}) | |
cache.init_app(app) | |
@cache.memoize(10) | |
def get_time(): | |
now = datetime.now() | |
print 'Generating...: {}'.format(datetime.now()) | |
time.sleep(5) | |
print 'Generated! : {}'.format(datetime.now()) | |
return now | |
@app.route('/') | |
def index(): | |
return '{} @ {}'.format(str(get_time()), datetime.now()) | |
if __name__ == '__main__': | |
app.run(host='0.0.0.0', port=int(sys.argv[1]), debug=True) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment