On Wednesday, December 21, 2016 at 1:12:26 AM UTC-5, 黄祥 wrote: > > learned about cache from the book, but got confused : > > 1. when tried to put cache affected for all functions in controller, the > cache.action have a strange behaviour >
First, it doesn't make sense to put cache.action at the top of the controller and pass it an empty lambda function -- it must decorate the actual function you want to cache so it can cache the content generated by that function. The lambda trick works with the auth.requires_login decorator because that decorator doesn't actually use the content of the decorated function -- it simply does a redirect before ever calling the decorated function if the user isn't logged in. > the controllers requires user to login, but it can by passed (not required > user logged in), > Yes, when you use cache.action, it caches the page in the user's browser (in addition to the server), so on subsequent requests, the user will simply reload the page from the browser (shouldn't be a problem though, as you already delivered that copy to them prior to the caching, which would have required login at that time). > 2. when using the cache.action why the key is encrypted, while test using > just cache on top of the controllers it shown the function name? > cache.action makes the key unique based on the details of the request, incorporating a number of items, such as the path, the view, the query string, the user agent, and the language. To avoid very long keys, it then hashes those items using MD5. If you'd like, you can add a prefix to the key (using the "prefix" argument) to help you identify it. 3. is it neccessary to put the cache in beside on top of the controller, > like in dal (select, iterselect, count, is_in_db) ? > What do you mean "in beside on top of the controller", and how does that relate to the use with the DAL? Anthony -- 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.

