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
upload separated = True:

def images():
    ''' get the image using its name
    param1 = table
    param2 = type (image,thumb,minithumb,logo,banner)
    param3 = name '''
    import os,time
    tabela =  request.args(0)
    tipo = request.args(1)
    nome_imagem = request.args(2)
    if tabela == 'artista':
        row = db.artista(image_filename=nome_imagem)
        image=row[tipo]
    elif tabela == 'personagem':
        row = db.personagem(image_filename=nome_imagem)
        image=row[tipo]
    elif tabela == 'novela':
        if tipo == 'logo':
            row = db.novela(logo_filename=nome_imagem)
        elif tipo == 'banner':
            row = db.novela(banner_filename=nome_imagem)
        image=row[tipo]
    if not image:
        raise HTTP(404)
    else:
        request.args.append(image)
    response.headers['Cache-Control'] = "max-age=604800" *# it is still
showing Cache-Control=0*
    #del response.headers['Pragma'] *# error, Pragma key not available*
    #del response.headers['Expires'] *# error, Expires key not available*
    splits = image.split('.')
    path = splits[0] + '.' + splits[1] + '/' + splits[2][:2] + '/'
    global_path = path + image
    filename = os.path.join(request.folder,'uploads',global_path)
    # send last modified date/time so client browser can enable client-side
caching
    response.headers['Last-Modified'] = time.strftime("%a, %d %b %Y
%H:%M:%S +0000", time.localtime(os.path.getmtime(filename)))
    return response.download(request,db)

I am pretty syre that  I am missing something here... using @cache-client
raised an "argument missing error", 0 given 1 expected...

How can I change my function to works with cache?

Thanks!

Tito



On Sat, Apr 6, 2013 at 11:19 AM, Niphlod <[email protected]> wrote:

> 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 no "improvement" to look for caching the results of a download()
> ^_^
>
>
> On Saturday, April 6, 2013 3:23:22 PM UTC+2, Massimo Di Pierro wrote:
>>
>> 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/**default/chapter/29/04#cache<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 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/favors client-side caching
>>>>    #7days
>>>>    response.headers['Cache-**Control'] = "max-age=604800"
>>>>    del response.headers['Pragma']
>>>>    del response.headers['Expires']
>>>>    filename = os.path.join(request.folder,'**uploads',request.args(0))
>>>>    # send last modified date/time so client browser can enable
>>>> client-side caching
>>>>    response.headers['Last-**Modified'] = time.strftime("%a, %d %b %Y
>>>> %H:%M:%S +0000", time.localtime(os.path.getmtim**e(filename)))
>>>>
>>>>    return response.stream(open(filename,**'rb'))
>>>>
>>>> this is the version I'm experimenting with. the original had a del
>>>> Cache Control instead of the max age. but google pagespeed still tells me
>>>> that no expiration date is set.
>>>>
>>>>
>>>> On Saturday, April 6, 2013 4:42:45 AM UTC+2, Tito Garrido wrote:
>>>>>
>>>>> Hi!
>>>>>
>>>>> I was running page speed on my website and all image files from the
>>>>> database (upload folder) are not cached...
>>>>> Is there a way to enable cache for them?
>>>>>
>>>>> Thanks!
>>>>>
>>>>> Tito
>>>>>
>>>>> --
>>>>>
>>>>> Linux User #387870
>>>>> .........____
>>>>> .... _/_õ|__|
>>>>> ..º[ .-.___.-._| . . . .
>>>>> .__( o)__( o).:_______
>>>>>
>>>>  --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 

Linux User #387870
.........____
.... _/_õ|__|
..º[ .-.___.-._| . . . .
.__( o)__( o).:_______

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to