hem....... cache.ram behaves differently than ANY other backend because it 
just stores a reference to the computed value .
That's why you can do a dict.update() without setting explicitely a new 
cached value....... but you'd need to do if you see it from a "flow" 
perspective.

What you are tryng to do in pseudo code is really:

.... if something_happens:
            search_cached_value
            if cached_value is not there:
                  calculate cached_value for all
                  store it in cache
            if just_a_piece_isn't_there:
                  fetch_cached_value
                  update_a_piece_of_it
                  store updated_cached_value into cache

and it is what you need to do with anything not being cache.ram (i.e. fetch 
"all", update a piece, store "the new all")

This difference of behaviours, and the lack of proper shortcuts is one of 
the things I hate most from web2py's cache behaviour (which has some pros, 
but lots of cons, like in your case). API for this kind of operations isn't 
really straightforward...


Wrapping things up....

if 'foo' not in globals():
    fetching = cache.whatever_but_not_ram('thekey', lambda:1, 
time_expire=None) # special case to never refresh the value
    if fetching == 1:
        # nobody ever stored something here
        huge_thing_to_compute = cache.whatever_but_not_ram('thekey', 
lambda: long_cache_func(), time_expire=0) #special case to ALWAYS refresh 
the value
    else:
       # something is stored here
       if needs_updating:
            fetching[just_a_piece] = 'newpiecevalue'
            cache.whatever_but_not_ram('thekey', lambda: fetching, 
time_expire=0)


BTW: I'm the only one thinking that you're overcomplicating the issue ? 
Just store pieces in cache and let them refresh when needed without dealing 
with the whole object and its relative invalidation (plus global escalation 
of local variables, etc etc etc)

BTW2: if you ask to store keys indefinitely, redis is happy to persist 
them. While cache.ram and cache.disk will effectively NEVER delete the 
values, redis has a strict upper value of one day (24*60*60) to avoid stale 
records everywhere.

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