Hi Everyone, I have some questions about how caching works in web2py. I'm not interested at this point in understanding how to cache entire views or anything like that - in this case, I'm interested in understanding the principles behind how web2py implements caching:
Let's say that I have a class that accepts some arguments that is defined like so: class SomeClass(): def __init__(self, arg1 = None, arg2 = None, arg3 = None): self.arg1 = arg1 self.arg2 = arg2 self.arg3 = arg3 if arg1 is not None: self.id_attribute = 'ID Value Here' + arg1 self = cache.ram(self.id_attribute, lambda self, time=(60*60*24* 30)) return self Now the *first* time I instantiate an object of SomeClass, say by calling: some_object = SomeClass(arg1=123, arg2=456, arg3=789) Then this will create an object of class "SomeClass", and (because arg1 is not None) will save that object to the cache (in ram) with the following attributes: some_object.arg1 == 123 some_object.arg2 == 456 some_object.arg3 == 789 some_object.id_attribute == 'ID Value Here123' Is the above so far correct? If so, then what happens if I perform an operation on some_object, like so: some_object.arg2 = 654 In this case: A. Does the cached object get updated: - if this statement gets executed < (60*60*24*30) seconds from when the object was instantiated? - if this statement gets executed > (60*60*24*30) seconds from when the object was instantiated? or: B. The local object gets updated, but the cached value does not change: - if this statement gets executed < (60*60*24*30) seconds from when the object was instantiated? - if this statement gets executed > (60*60*24*30) seconds from when the object was instantiated? or: C. Something else? And then what happens when I have some other function try to "do something" using some_object? some_other_value = some_object.arg2 + 987 Specifically, does the value of some_object.arg2 get read from the cache or from the object itself: - if this statement gets executed < (60*60*24*30) seconds from when the object was instantiated? - if this statement gets executed > (60*60*24*30) seconds from when the object was instantiated? And finally, if I wish to force a changed value of some_object to be saved to the cache, am I correct that I should then call: some_object.arg3 = 1111 some_object = cache.ram(self.id_attribute, lambda self, time=0) which will explicitly change the cached version of some_object? Does this mean that the next time someone instantiates an object of class "SomeClass" with the same arg1 value but a different time_expire value, the cached object will be overwritten? Any help / clarification / explanation would be much appreciated! Thanks in advance, Chris -- 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.