Skip to content

Instantly share code, notes, and snippets.

@TheWaWaR
Created August 17, 2015 03:00
Show Gist options
  • Save TheWaWaR/767480a45bbc4bef0b6c to your computer and use it in GitHub Desktop.
Save TheWaWaR/767480a45bbc4bef0b6c to your computer and use it in GitHub Desktop.
Test flask cache concurrency.
#!/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