Hello, If you have some concern about when the cached value will be update in order to make sure your users get the latest correct information you can just clear cache where in your code you want that the value to be caching get "re-cache" (or update)
Here how to do it : "This is a good point. For things that may not change a whole lot, I usually set the time_expires=3600 or even None. Give the key a well-defined name, and then when something changes, run cache.ram.clear(key) so that the next query will get the changes." Worte by Ross in this thread : https://groups.google.com/forum/?fromgroups#!topic/web2py/FWS8kstJHCU So, let say you have this cached value create in models somewhere to make sure they are always available : # Model var_name_dict = cache.ram('var_name_dict', lambda: dict([(r.field1_name,r.field2_name)\ for r in db().select(db.table_name.ALL)]), time_expire=3600) # Controller def function_that_request_up_to_date_var_name_dict(): cache.ram.clear(var_name_dict) ... I think you can just call the cached var and it will be recached, but it could be possible that you have to rebuild the cached var once you clear the cache, but I don't think so. Richard On Thu, Jul 12, 2012 at 11:47 PM, david xiao <[email protected]>wrote: > Hi, > I am new to web2py these 2 days, while i am confused about how to > update the cached value when i read the manual, the below section. > as it explains: > *the value "Hello" will be retrieved from the cache, and it will not > be updated with "Goodbye"*. > Does it means the second statement just have set the time_expire, not > update the value with "Goodbye"? > Does it means "Hello" exists still after 5 second set in the first > statement ? > How to update the cached vaule if want, like to set "Goodbye" to > replace "Hello"? > > Thanks > > 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: > 1 message = cache.ram('message', lambda: 'Hello', time_expire=5) > > Now, suppose the following call is made 10 seconds after the above call: > 2 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. >

