Re: [web2py] Re: how to avoid an overhead

2013-04-23 Thread Richard Vézina
Ok, I see... I would experiment something else then cache.ram.clear() since it seems invasive and my users fall a couple of time on empty dict or something like that. I thought that setting the expire tiem to 0 could be less invasive (I mean not delete the variable)... An other thing is that I w

Re: [web2py] Re: how to avoid an overhead

2013-04-23 Thread Anthony
I don't know what you're trying to do, but I was responding to Martin's request, which required doing a lot of processing at form creation time that he didn't want to repeat at processing time -- so the idea was to calculate and cache at form creation time and then read from the cache when the

Re: [web2py] Re: how to avoid an overhead

2013-04-23 Thread Richard Vézina
I was more asking explanation to Anthony about it suggestion on how to update cache... I think Martin has find a solution, since that time! :) Richard On Tue, Apr 23, 2013 at 4:22 PM, Derek wrote: > Why not have a different function create the form, and use a cache > decorator? > @cache('crea

Re: [web2py] Re: how to avoid an overhead

2013-04-23 Thread Derek
Why not have a different function create the form, and use a cache decorator? @cache('createExpensiveForm',time_expire=3600,cache_model=cache.ram) def createExpensiveForm() form = expensive calculations here() return form then your mypage would look like so: def mypage() form=createE

Re: [web2py] Re: how to avoid an overhead

2013-04-23 Thread Richard Vézina
Anthony, I maybe wrong, but I am not sure I understand correctly your example here... Or maybe you suggest this for an other reason... But to me you want to refresh cash when the form is submit and the value change (since what I am caching is a dict of id and reprensetnation)... I think it make mo

[web2py] Re: how to avoid an overhead

2012-09-27 Thread Anthony
On Thursday, September 27, 2012 1:27:42 PM UTC-4, MichaelF wrote: > > By 'cache' do you mean a session variable (or several)? Wouldn't that work? > If the stored values are specific to a given user/session, then yes, the session would be the right place. If they are general values that don't dep

Re: [web2py] Re: how to avoid an overhead

2012-09-27 Thread Anthony
> > var_name = cache.ram('var_name', lambda: do_something, time_expire=3600) > > You can then clear the cache like this : > > cache.ram.clear(var_name) > You can also do: expire = 3600 if request.post_vars else 0 var_name = cache.ram('var_name', lambda: do_something, time_expire=expire) So, wh

Re: [web2py] Re: how to avoid an overhead

2012-09-27 Thread Richard Vézina
I think he mean : var_name = cache.ram('var_name', lambda: do_something, time_expire=3600) You can then clear the cache like this : cache.ram.clear(var_name) Richard On Thu, Sep 27, 2012 at 1:27 PM, MichaelF wrote: > By 'cache' do you mean a session variable (or several)? Wouldn't that work

[web2py] Re: how to avoid an overhead

2012-09-27 Thread MichaelF
By 'cache' do you mean a session variable (or several)? Wouldn't that work? On Thursday, September 27, 2012 8:00:59 AM UTC-6, Anthony wrote: > > I suppose it depends on whether all the calculations and db accesses are > needed for the processing as well as the initial creation. If not, you > cou

[web2py] Re: how to avoid an overhead

2012-09-27 Thread Anthony
I suppose it depends on whether all the calculations and db accesses are needed for the processing as well as the initial creation. If not, you could do something like: if not request.post_vars: form = a_lot_of_calculations_and_db_accesses() else: form = minimal_form_without_all_the_calc