AFlaskextensionwithlotsofcommontime-savers(file-serving,favicons,etc).
Anexampleapp:
importtimefromflaskimportFlaskfromflask_commonimportCommonapp=Flask(__name__)app.debug=Truecommon=Common(app)@app.route("/")@common.cache.cached(timeout=50)defhello():time.sleep(1)return"HelloWorld!"if__name__=="__main__":common.serve()Next:
Putafavicon.icoinyourstaticfolder.Enjoy!NicitiesHTTPHeaders:
X-Powered-By:Flask.X-Processed-Time:0.000133037567139.Othernicethings:
@common.cache.cached(timeout=50)decoratorforcachingviewsinmemory.Faviconsupport(/favicon.icoredirectsto/static/favicon.ico).WebServer:Gunicorn+MeinheldAutomaticallyusesGunicorn+Meinheldforproduction(whenFlask.debug=False),Flask'sdevserverfordevelopment.
Configurationenvironmentvariables:
WEB_CONCURRENCYforspecifyingthenumberofsynchronousgunicornworkers.PORTforbindingtoaspecificport.FileServer:WhiteNoiseFlask-CommonautomaticallyconfiguresWhiteNoisetoserveyourstaticfiles.
Configurationsapp.config['COMMON_FILESERVER_DISABLED']=1app.config['COMMON_POWERED_BY_DISABLED']=1app.config['COMMON_PROCESSED_TIME_DISABLED']=1CacheconfiguresBydefaultsimpleisadefaultcachetype.Butcanyouchangethisoptions,followingbelowsteps.Flask-Caching
app.config['COMMON_CACHE_TYPE']="simple"
评论