here book description from
http://web2py.com/books/default/chapter/29/04/the-core#cache :

Note, time_expire is used to compare the current time with the time the 
requested object was last saved in the cache. It does not affect future 
requests. This enables time_expire to be set dynamically when an object is 
requested rather than being fixed when the object is saved. For example:



message = cache.ram('message', lambda: 'Hello', time_expire=5)
 

Now, suppose the following call is made 10 seconds after the above call:



message = cache.ram('message', lambda: 'Goodbye', time_expire=20)
 

*Because time_expire is set to 20 seconds in the second call and only 10 
seconds has elapsed since the message was first saved, the value "Hello" 
will be retrieved from the cache, and it will not be updated with 
"Goodbye". The time_expire value of 5 seconds in the first call has no 
impact on the second call.*

Setting time_expire=0 (or a negative value) forces the cached item to be 
refreshed (because the elapsed time since the last save will always be > 
0), *and setting time_expire=None forces retrieval of the cached value*, 
*regardless 
of the time elapsed since it was saved* (if time_expire is always None, the 
cached item will effectively never expire).


now with cache.redis:


def acache():
    cache.redis('message', None)
    message = cache.redis('message', lambda: 'Hello', time_expire=5)
    sleep(10)
    v = cache.redis('message', lambda: 'Goodbye', time_expire=20)
    return locals()


result:

v=*'Goodbye'*



using *time_expire=None* to retrieve cached value:


def bcache():
    cache.redis('message', None)
    message = cache.redis('message', lambda: 'Hello', time_expire=5)
    sleep(10)
    v = cache.redis('message', lambda: 'Goodbye', time_expire=None)
    return locals()

result:

v=*'Goodbye'*


I'd like to cache user specific values for the user session period:


message = cache.redis('avalue', lambda: value, time_expire= 
auth.settings.expiration)


how do I make sure value can be retrieved ?

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to