El martes, 18 de marzo de 2014 09:30:34 UTC-3, Anthony escribió:
>
>  - How can I verify when the html was actually retrieved from the cache? I 
>> tried coding a "print request.now" in the view, but that sentence is 
>> executed everytime I hit the site's homepage, so I deduce that the code 
>> that generates the html is executed everytime I hit the home instead of 
>> retrieving from the cache. However, I'm not sure if that "print 
>> request.now" is a correct indicator.
>>
>
> The cache decorator just caches the output of the controller function, not 
> the final HTML output. If you want to do the latter, then you should have 
> the function itself directly call response.render() and return that (this 
> technique is mentioned in the book).
>

Oh I see, I guess I missed that part, my bad. Now I'm getting the expected 
behaviour. 

>  
>
>>  - Is it possible to use server-side cache of the view but **not** 
>> browser side? I'm specially interested in caching the view server-side, but 
>> not browser-side.
>>
>
> According to the documentation, this should be possible, but looking at 
> the code, I'm not sure it actually is. Anyway, as long as you're caching on 
> the server, why not also let the browser cache the page?
>

True. I just had the doubt because I also read in the docs that it could be 
possible, but not shure how. However I'm not interested in browser-side 
cache for now.

>  
>
>>  - Users can login in my site, but homepage isn't different for logged in 
>> users, only thing that's different is topbar showing the name of logged in 
>> user. Is it still possible to use @cache.action?
>>
>
> Yes, but you'd want to set session=True to make sure each user gets a 
> different page. In that case, though, you probably would not want to do 
> server side caching, as you will be continually adding to the cache with no 
> benefit over client-only caching. Also, keep in mind that values are not 
> automatically deleted from the cache (even after they expire), so you don't 
> want to accumulate an potentially unlimited number of cache items (you'll 
> at least need to do some periodic cleanup).
>

Yes, actually I was thinking setting session=True for every user, but using 
cache_model=cache.ram just when the user isn't logged in. 

After your tips and a few tests, now I understand better. Now my goal is 
this: I want to cache server-side the rendered view **excluding the 
extended layout**, that is, I have a layout.html and index.html extends the 
layout. The layout has things that I don't want to be cached (for example, 
user's navbar).  I think in this case @cache.action is not going to work 
(because it will cache the complete rendered view).

However, I managed to achieve what I want, doing this:

 - A "layout.html" containing user's navbar and site's header and footer. 
 - An "index.html" that extends layout.html
 - An "content.html" that **doesn't** extends layout.html
 - An index() controller function that **doesn't** use @cache.action 
decorator. Instead, the function uses response.render() specifying 
"content.html" as the view file to be rendered, and stores the results of 
the rendering in the cache. That result is passed as a variable to 
"index.html" view.

In this way, I'm getting the behaviour I want, which is: caching just a 
portion of the site's homepage. If you see that something is "wrong" with 
this approach, please let me know. Until now tests have been ok. Thanks for 
your help!


> Anthony
>
>

-- 
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 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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to