librelist archives

« back to archive

[Code review ]: Caching a function for a day

[Code review ]: Caching a function for a day

2013-12-14 @ 18:33
I am writing a flask app that I will deploy it on Heroku to test it. 
There is a page that will generate daily photos and information based on 
a JSON file. The view is valid for 24 hours beginning from 00:00 to 
23:59 of everyday.

I am thinking about using a cache, otherwise the app will consume 
unnecessary resources.

The is the code :

|import  ..


  app=  Flask(__name__)
  app.jinja_env.auto_reload=  False
  cache=  Cache(config={'CACHE_TYPE':  'simple',  'CACHE_ARGS'  :  TODAY})
#This function reads a json file, filter the daily data to process and 
render a html template with photos and text .

# 3600 *  24 = 86400
def  inf():
     input_file=  open(os.path.join(__location__,  'json/output.json'));     
     j=  json.loads("utf-8-sig"))

     return  render_template('inf.html',  
                         title=  title,

if  __name__==  '__main__':
     if  TODAY!=  cache.config['CACHE_ARGS']  :
         with  app.app_context():
     port=  int(os.environ.get('PORT',  33507))  True,  host='',  port=port)


I am not sure if this is the best solution to cache the view for a day. 
That's why I am asking here for more suggestions. Thanks in advance .

Aymen Amri