it's kinda chicken-and-egg here, because your real trouble is that the 
unlogged user hits a page that you want to be cached client-side as long as 
he is not logged in.
if you let it cache client-side, having the user returning to the same page 
to expect a different outcome is impossible. 
IMHO the solution is that you should refactor your app to present a proper 
"landing page" uri for public viewers and a separate one for logged in 
users. 

On Monday, June 6, 2016 at 7:10:51 PM UTC+2, Lisandro wrote:
>
> I've been doing some more test and a bit more reading about this, and I 
> can see (if I'm not wrong) that this is not a problem, it's the expected 
> behaviour.
> @cache.action does precisely that: it sets cache headers for client-side 
> caching, that is, browser side caching. 
> And, *optionally*, it allows you to set server-cache also (using a 
> cache.model, like ram, disk or redis).
>
> So, using @cache.action, the user (without being logged) visits a page and 
> the browser stores the view in cache. 
> Then the user logs in, and returns to the previously visited page, and the 
> browser uses the copy in local caché.
>
> I've read that I could use the old (but still perfectly valid) method of 
> @cache decorator.
> However @cache.action has some facilities to handle vars and session. wich 
> aren't present with @cache
>
>
> The whole point of this was to avoid an extra ajax call from the views.
> I was using the same cached view for all users, and the HTML returned to 
> the browser had an ajax call that loaded the user menu. 
> However. this meant that the models were executed twice per every page 
> visit, and that wasn't very good, also I'm trying to save CPU.
>
> I'll try to figure out if there is an alternative.
>
>
>
> El lunes, 6 de junio de 2016, 10:26:35 (UTC-3), Lisandro escribió:
>>
>> I need to decorate a controller function with @cache.action in order to 
>> have two different versions of the rendered view: one for logged-in users 
>> and another one for not logged-in users.
>>
>> Notice that I don't need one different caché for each user (that could be 
>> achieved using session argument). 
>> Instead, what I need is two versions of the rendered view: one for all 
>> the users that aren't logged-in, and one for all the users that are 
>> logged-in.
>> The only difference between those two versions of the rendered view is 
>> that one of them includes a top navbar, which is is the same for all 
>> logged-in users, but it shouldn't be present in the cache version for not 
>> logged-in users.
>>
>>
>> Because I need the same behaviour in several controller functions, the 
>> way I do it is defining the @cache.action parameters at the models level, 
>> like this:
>>
>> CACHE = Storage()
>> CACHE.prefix = ''
>> CACHE.time_expire = 300
>> CACHE.public = True
>> CACHE.session = False
>> CACHE.vars = False
>> if auth.is_logged_in():
>>     CACHE.prefix += 'logged-in-'
>>     CACHE.public = False
>>     # CACHE.model = None
>>
>>
>> The I use that configuration in controller functions:
>>
>> @cache.action(time_expire=CACHE.time_expire, cache_model=CACHE.model, 
>> session=CACHE.session, vars=CACHE.vars, public=CACHE.public, prefix=CACHE
>> .prefix)
>> def index():
>>     return response.render(...)
>>
>>
>> @cache.action(time_expire=CACHE.time_expire, cache_model=CACHE.model, 
>> session=CACHE.session, vars=CACHE.vars, public=CACHE.public, prefix=CACHE
>> .prefix)
>> def forum():
>>     return response.render(...)
>>
>>
>>
>> However, I'm having trouble to make it work as I want. 
>> It's not working entirely wrong, but the problem is this:
>>   1) the user hits the index, without being logged-in;
>>   2) the user logs in
>>   3) the user goes back to index, but still sees the cached page (I think 
>> it's the browser that is using local cache). If the user reloads the page 
>> (hitting F5 or Ctrl+R), then the new view is shown.
>>
>>
>> What am I missing?
>>
>> As you can see in the code, I've tried:
>>  - setting public=False regardless of the logged in state;
>>  - setting cache.model=None when the user is logged-in;
>>  - using a different prefix for logged in users;
>>
>> But the problem remains: after logging in, the user need to hit F5 in 
>> order to see the other view.
>>
>>
>> As always, I will appreciate any help on this.
>> Regards, Lisandro
>>
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to