I'm using Apache & mod_wsgi I'm looking at the other thread that massimo suggests changes to apache.conf, but after using fast_download (changing headers and using stream) it runs really quickly!
(I know, serving through apache would be even faster, but in this case I prefer portability and a easy configuration) You can see how it's running here: http://www.pyday.com.ar/rafaela2010/ (look at images at the sidebar) Thanks so much, Mariano Reingart http://www.web2py.com.ar http://www.sistemasagiles.com.ar http://reingart.blogspot.com On Tue, May 4, 2010 at 11:55 PM, Thadeus Burgess <[email protected]> wrote: > What webserver are you using? > > You could use the X-Sendfile header if it supports it. This way the > webserver will send cache headers and web2py does not have to serve > them. > > -- > Thadeus > > > > > > On Tue, May 4, 2010 at 9:25 PM, mdipierro <[email protected]> wrote: >> response.stream (which you use) handles if-modified-since and range >> requests automatically. >> >> On May 4, 9:04 pm, Mariano Reingart <[email protected]> wrote: >>> I thought so, >>> >>> I had to modify mydownload so browsers do client-side caching, >>> speeding up the web-page load: >>> >>> def fast_download(): >>> # very basic security: >>> if not request.args(0).startswith("sponsor.logo"): >>> return download() >>> # remove/add headers that prevent/favors caching >>> del response.headers['Cache-Control'] >>> del response.headers['Pragma'] >>> del response.headers['Expires'] >>> filename = os.path.join(request.folder,'uploads',request.args(0)) >>> response.headers['Last-Modified'] = time.strftime("%a, %d %b %Y >>> %H:%M:%S +0000", time.localtime(os.path.getmtime(filename))) >>> return response.stream(open(filename,'rb')) >>> >>> TODO: handle If-Modified-Since (returning 304 if not modified), but as >>> you said, let the browser do that if so much performance is needed (so >>> far, fast_download is working fine for me now :-) >>> >>> Thanks very much for your help, and please let me know if there is >>> anything wrong with this approach, >>> >>> Best regards, >>> >>> Mariano >>> Reingarthttp://www.web2py.com.arhttp://www.sistemasagiles.com.arhttp://reingart.blogspot.com >>> >>> On Tue, May 4, 2010 at 10:23 PM, mdipierro <[email protected]> wrote: >>> > caching downloads does not make sense. This is because the role of >>> > download is to check permissions to download a file (if they are set). >>> > if you cache it then you do not check. If you do not need to check do >>> > not use download. Use >>> >>> > def mydownload(): >>> > return >>> > response.stream(open(os.path.join(request.folder,'uploads',request.args(0)),'rb')) >>> >>> > or better use the web server to download the uploaded files. >>> >>> > On May 4, 6:11 pm, Mariano Reingart <[email protected]> wrote: >>> >> To cache images, I'm trying to do: >>> >>> >> @cache(request.env.path_info,60,cache.ram) >>> >> def download(): return response.download(request,db) >>> >>> >> But seems that is not >>> >> working:http://www.web2py.com.ar/raf10dev/default/index >>> >> (see images at sidebar, if you quickly reload pages, they fail) >>> >>> >> The book says something about response.render, but nothing about >>> >> download... >>> >> Anyway, I'm not sure if this is a good use of @cache, are there any >>> >> other way ? >>> >>> >> BTW, why Cache-Control: no?... >>> >>> >> Best regards, >>> >>> >> Mariano >>> >> Reingarthttp://www.sistemasagiles.com.arhttp://reingart.blogspot.com >> >

