[web2py] Re: Is there a way to cache images from "download" function?

2020-06-25 Thread Andrew Rogers
Hi I tried this from the book, but got an error: @cache.action(time_expire=874, cache_model=cache.ram, session=True, vars=True, public=True) So i tried the ideas in this post and they had miscellaneous errors. I thought things have probably changed since 2014. Then i started removing parame

[web2py] Re: Is there a way to cache images from "download" function?

2014-01-29 Thread Niphlod
server-side it doesn't make any sense, so there's no native way to do it. It's not going to be faster than serving a static-file. On Wednesday, January 29, 2014 12:53:00 AM UTC+1, James Burke wrote: > > I'm exploring options. > > I want to be able to cache my images. Client side, server side it

[web2py] Re: Is there a way to cache images from "download" function?

2014-01-28 Thread James Burke
I'm exploring options. I want to be able to cache my images. Client side, server side it doesn't matter. What is the best method to go about this? -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google

[web2py] Re: Is there a way to cache images from "download" function?

2014-01-28 Thread Niphlod
wasn't the original point just to add the proper headers ? Of course you can't cache a generator (that is what response.stream returns) It makes no sense at all to store the actual contents of the file on memcache On Tuesday, January 28, 2014 7:46:18 PM UTC+1, James Burke wrote: > > Ok I tried:

[web2py] Re: Is there a way to cache images from "download" function?

2014-01-28 Thread James Burke
Ok I tried: @cache.action(time_expire=1200, cache_model=cache.memcache, quick='SVL') def fast_download(): import time, os import contenttype as c # very basic security: if not request.args(0).startswith("file.file"): return download() file_id = request.args(-1)

[web2py] Re: Is there a way to cache images from "download" function?

2014-01-28 Thread Niphlod
lots and lots of time passed under the bridge. Now there's cache.action ... > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received

[web2py] Re: Is there a way to cache images from "download" function?

2014-01-27 Thread James Burke
Version 2.7.4-stable+timestamp.2013.10.14.15.16.29 recent enough? It's after your original post. On Tuesday, January 28, 2014 2:49:52 AM UTC+13, Niphlod wrote: > > probably you're not running a recent web2py release. > > On Saturday, January 25, 2014 9:37:12 PM UTC+1, James Burke wrote: >> >> def

[web2py] Re: Is there a way to cache images from "download" function?

2014-01-27 Thread Niphlod
probably you're not running a recent web2py release. On Saturday, January 25, 2014 9:37:12 PM UTC+1, James Burke wrote: > > def fast_download(): > import time, os > import contenttype as c > > cache.client(time_expire=604800, quick='SVL')(lambda: 0)() > > file_id = request.arg

[web2py] Re: Is there a way to cache images from "download" function?

2014-01-25 Thread James Burke
I tried using the above code, but results in the follow error message: cache.client(time_expire=604800, quick='SVL')(lambda: 0)() AttributeError: 'Cache' object has no attribute 'client' Am I missing something? Cheers -James On Monday, April 15, 2013 1:21:18 AM UTC+12, Niphlod wrote: > >

[web2py] Re: Is there a way to cache images from "download" function?

2013-04-14 Thread BlueShadow
It works like a charm. I used the stream function and that works too. #7days def fast_download(): session.forget(response) cache.client(time_expire=604800)(lambda: 0)() # very basic security (only allow fast_download on your_table.upload_field): if not request.args(0).startswith("db.Im

[web2py] Re: Is there a way to cache images from "download" function?

2013-04-14 Thread Niphlod
ok. So, basically the problem is that response.stream is a "special" kind of function. It raises HTTP(200, content_of_the_file) instead of returning it, and raising an HTTP(200) is a smart way to do it. Unfortunately, this means that def download(): return response.stream() basically d

[web2py] Re: Is there a way to cache images from "download" function?

2013-04-14 Thread Niphlod
sorry for the misguidance unfortunately response.stream doesn't return , it raises HTTP() so basically the cache decorator hasn't the possibility of completing. I'm looking into it right now. -- --- You received this message because you are subscribed to the Google Groups "web2py-users"

[web2py] Re: Is there a way to cache images from "download" function?

2013-04-14 Thread BlueShadow
So I changed my function to this: #7days @cache.client(time_expire=604800, quick='SVL') def fast_download(): session.forget(response) # very basic security (only allow fast_download on your_table.upload_field): if not request.args(0).startswith("db.Images"): return download() #

Re: [web2py] Re: Is there a way to cache images from "download" function?

2013-04-06 Thread Tito Garrido
Now it works! I just changed the return function to return response.stream(open(filename,'rb')) :D Thanks folks! PS: How to use @client-cache? :) Regards, Tito On Sat, Apr 6, 2013 at 1:36 PM, Tito Garrido wrote: > Hi Folks! > > Thanks for your answers but my implementation is a little bit d

Re: [web2py] Re: Is there a way to cache images from "download" function?

2013-04-06 Thread Tito Garrido
Hi Folks! Thanks for your answers but my implementation is a little bit different so none of the solutions above worked, I have tried to adapt the slice solution but it didn't work also, here is my "download" function, I am using the name of the files instead of the hash name (I am also using uplo

[web2py] Re: Is there a way to cache images from "download" function?

2013-04-06 Thread Niphlod
cache.client (when no cache_model is passed) just sets headers (that's the idea at the bottom). When you pass a cache_model, it sets headers AND cache the results (and that's the "idea at the top"). cache.client was created in the first place to avoid having to set headers repeatedly. There's

[web2py] Re: Is there a way to cache images from "download" function?

2013-04-06 Thread Massimo Di Pierro
Does that work for download? Download returns a stream not a string. On Saturday, 6 April 2013 06:48:55 UTC-5, Niphlod wrote: > > there's a new @cache.client decorator to set expire headers in an easy way > > as soon as the book gets updated the docs will be here > http://web2py.com/books/d

[web2py] Re: Is there a way to cache images from "download" function?

2013-04-06 Thread Niphlod
there's a new @cache.client decorator to set expire headers in an easy way as soon as the book gets updated the docs will be here http://web2py.com/books/default/chapter/29/04#cache On Saturday, April 6, 2013 11:58:17 AM UTC+2, BlueShadow wrote: > > There supposedly is a way the fast downlo

[web2py] Re: Is there a way to cache images from "download" function?

2013-04-06 Thread BlueShadow
There supposedly is a way the fast download function(web2pyslices) def fast_download(): # very basic security (only allow fast_download on your_table.upload_field): if not request.args(0).startswith("db.your_table.your_field"): return download() # remove/add headers that prevent/fa