Or you could use a caching proxy, like Squid (if I had a penny...) and put your cache-control header emitting webapp behind that. It will take care of this and all your future caching needs in a fully HTTP compliant manner and make your website as fast as a collection of static pages if properly configured. You can easily let Squid verify that the source has not changed on every request without needing to actually regenerate the thumbnail, or you can make the window a specified number of seconds large and live even more caching happiness.
Disk space and memory used for caching, configuration, caching security considerations, correct functionality and HTTP compliance: everything unified in one program. Keep all that unnecessary clutter out of your app. Needless to say, I am a big proponent of this setup and can not even really imagine how anyone would set up a serious web.py app without it. Maybe your website isn't all that serious, of course. In which case you do not need caching in the first place, not in your either. I have yet to come across a situation where actually doing /any/ caching inside an app instead of with a caching proxy was anything else than a bad idea. If somebody can enlighten me, please. Greetings, Hraban 2010/12/11 andrei <[email protected]>: > I don't like your implementation, you should cache generated images and let > them be downloaded as static content. > For my site I implemented helper function for template. It accepts image > database object (with original filename) and size as params, then it checks > if specific size was already generated, if not — then it generates thumbnail > of needed size, saves it into static folder, and then returns url to the > image, which is then served from static folder. > > > > As for file streaming, I had a case where I need to forbid access to some > files and so the cannot be put into static folder. To stream file the i used > generator which is supported in webpy. (I use web.auto_application for url > mapping): > class DownloadFile(app.page): > > path="/(users|tenders)/(\d+)/files/(\d+)" > > def GET(self, obj_type, obj_id, file_id): > obj = db.select(obj_type, vars=locals(), where="id=$obj_id", > limit=1)[0] > return self.get(obj, obj_type, obj_id, file_id) > > �...@file_download_access > def get(self, obj, obj_type, obj_id, file_id): > doc = db.select("files", locals(), where="id=$file_id and > obj_type=$obj_type and obj_id=$obj_id", limit=1)[0] > web.header("Content-Disposition", "attachment; filename=%s" % > doc.filename) > web.header("Content-Type", doc.filetype) > web.header('Transfer-Encoding','chunked') > f = open(os.path.join(config.upload_dir, doc.path, doc.filename), > 'rb') > while 1: > buf = f.read(1024 * 8) > if not buf: > break > yield buf > > -- > You received this message because you are subscribed to the Google Groups > "web.py" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/webpy?hl=en. > -- You received this message because you are subscribed to the Google Groups "web.py" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/webpy?hl=en.
