Maybe this would work:

cache.ram('MyValue',
          lambda: getvalue() or cache.ram('MyValue', lambda: None,time_expire
=None),
          time_expire=60*60*24)

Calling cache.ram() with time_expire=None always retrieves the currently 
stored value, so you can assign that if getvalue() returns None (I'm 
assuming when getvalue() works it doesn't return other types of Falsey 
values -- if so, then you'll have to test specifically for None).

Another option might be to change the getvalue() function directly 
(assuming it makes sense to encode the cache key into it):

def getvalue():
    try: 
        return function_that_may_not_complete()
    except:
        return cache.ram("MyValue", lambda: None, time_expire=None)

Anthony

On Friday, March 22, 2013 9:32:16 AM UTC-4, villas wrote:
>
> 1. How can I view a currently cached value,  without any possibility of 
> changing it?
>
> 2. Say I have this code:
>
> def getvalue():
>     try: 
>         return function_that_may_not_complete()
>     except:
>         return None
>         
> cache.ram('MyValue', lambda: getvalue(), time_expire=60*60*24) 
>
>
> If my getvalue()  function returns none,  I assume the cache will be 
> cleared.  I do not want that to happen.
> If  getvalue()returns None,  I want to re-cache the same value.
>
> Hope the above makes sense.
> Thanks
>
>
>
>

-- 

--- 
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/groups/opt_out.


Reply via email to