Thanks Niphlod and Anthony! That answered my question about caching views 
with database selects. However, my problem with client-side caching 
differently for logged-in and non-logged in users is still a problem.

Niphlod, I'm not sure what you're referring to by the "user" parameter. The 
closet parameters to "user" would be "session" and "public". But I don't 
see these options helping to differentiate between logged in and non-logged 
for caching. Doesn't "session" only add a session id key for server-side 
caching, and "public" only determine whether a cache is useable on a single 
user's machine, or the user's network?

Anthony, my problem still persists with your code; the "public" parameter 
does not seem to be the proper parameter for this problem.

For example, when a user first hits the page (not logged-in), the public 
parameter will be set to True. This will cache the page in it's non-logged 
in state. If the user then logs in, and hits the page again, the browser 
will serve the non-logged-in version of the page from cache.

No matter what the value of "public" is (unless the browser doesn't cache 
at all for public=false), if the user hits the page in either 
logged-in/non-logged in state, and goes to the same page later in the 
opposite state, the browser will serve the previously cached version of 
that page (which will be in the wrong logged-in/non-logged in state).

The "public" parameter, if set to False, is helpful in preventing cached 
logged-in versions of the site from being the same across users. However, 
for each user, it does not help differentiate between logged in and 
non-logged cache pages.


I've done some more research, and there doesn't seem to be any 
straightforward or practical ways of doing this. The main problem is that 
the browser can't tell whether a cached page is logged-in/not-logged in 
(since it's the same URL). Let me know if I'm missing something here, I'd 
like to take advantage of cache.action.



On Monday, October 21, 2013 6:07:56 AM UTC-7, Anthony wrote:
>
>
> For users who aren't logged in, the pages would be the same. However, if a 
>> user is logged in, then there are links to the users' profile, as well as a 
>> logout link; thus making the page different for every user, and different 
>> for logged-in vs. non-logged-in users. Is there any way to effectively 
>> cache these pages, or only cache the non-logged in page for non-logged in 
>> viewers?
>>
>
> cache.action does two things -- it sends appropriate response headers to 
> the browser to enable client-side caching, and it (optionally) does 
> server-side caching via the web2py cache mechanism. You might want to avoid 
> doing per-user server-side caching, as that will start to fill up server 
> memory, and you'd have to make sure you manually clear cached values 
> periodically. Maybe consider something like:
>
> @cache.client(cache_model=cache.ram if not auth.is_logged_in() else None,
>               public=not auth.is_logged_in(), ...)
>
> That will do server-side caching of the non-logged-in page only, and it 
> will set public client-side caching to False for logged in users.
>  
>
>> Secondly, cache.action can't be used to cache views with database 
>> selects. However, if the database select was converted to a list/dict, with 
>> as_list() or as_dict(), would caching the page with cache.action be 
>> possible (this would make it pickleable as a regular dictionary)?
>>
>
> Not sure what you mean -- can you show some code? cache.action caches only 
> the output of the decorated function (and only if cache_model is specified 
> -- otherwise, all it does is send headers to the browser to enable 
> client-side caching).
>
> 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/groups/opt_out.

Reply via email to