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 would greatly perfer to be DRY and keep the
clearing mechanism to be as close as possible to the sentence that create
the dict.

So, I thought about something like this :

# In model (not tested)
if request.args(0) == 'table_name' and request.controller ==
'controller_name' and request.function == 'function_name' and
request.post_vars:
    expire = 0
else:
    expire = 3600
dict_name = cache.ram('dict_name', lambda: dict_creation...,
time_expire=expire)

Richard



On Tue, Apr 23, 2013 at 4:42 PM, Anthony <abasta...@gmail.com> wrote:

> 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 form is submitted/processed. If you are doing something else, then of
> course this may not make sense for you.
>
> Anthony
>
>
> On Tuesday, April 23, 2013 4:10:38 PM UTC-4, Richard wrote:
>
>> 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 more
>> sens like this :
>>
>> expire = 3600 if not request.post_vars else 0
>>
>> ??
>>
>> Thanks
>>
>> Richard
>>
>>
>> On Thu, Sep 27, 2012 at 2:15 PM, Anthony <abas...@gmail.com> wrote:
>>
>>> var_name = cache.ram('var_name',  **lambd**a: 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, when the form is created, time_expire will be 0, which forces the
>>> value to be refreshed.
>>>
>>> Anthony
>>>
>>>  --
>>>
>>>
>>>
>>>
>>
>>  --
>
> ---
> 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.
>
>
>

-- 

--- 
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