On Wednesday, December 21, 2016 at 5:09:53 PM UTC-5, 黄祥 wrote: > > thanks anthony, for detail explaination. > 1. in controllers usually contain more than 1 function so i think it'll be > efficient to put it on top of the controllers like i usually do with > auth.requires_login(), i've tested both no errors occured : > e.g. > #cache.action(time_expire = 300, cache_model = cache.ram, quick = > 'SVLUP')(lambda: None)() > cache.action(time_expire = 300, cache_model = cache.ram, quick = 'SVLUP') > > my question is it recommended to put the cache on top of the controllers > that affect to all the function in that controller? >
Please read my previous explanation -- putting cache.action at the top of the controller will not result in the page being stored or served from the server cache. It will not generate an error, and (I think) it will properly set the headers for client-side caching, but you won't get any server-side caching if that's what you want. You will get an entry in the server-side cache, but it will simply be None (which is what your lambda function returns), and it won't actually be used to serve the page. Do not do this. > 2. "in beside on top of the controller" is put the cache on top of the > controllers so that it can affect to all function in that controllers, the > correlation for the DAL cache is should i pick one or both (DAL cache and > cache.action) ? > If you're caching the entire page, there is no need to also cache the DAL query. But if the same query is used in multiple places or you are caching multiple versions of the page (e.g., based on query string, language, user agent, etc.), then caching the query (assuming it doesn't change) could also be helpful. > 3. in the book it said : > For example, when you show a form to the user, or a list of records, the > web page should not be cached, as other users may have inserted new records > on the table you are showing. > > ref: > > http://web2py.com/books/default/chapter/29/04/the-core?search=cache#cache-action > > let say, i have a web app that contain 3 parts : > - master (e.g. product, customer) > - transaction (e.g. sale order) > - report (e.g. sale order) > > so base on the book said, the webapps better not use cache because all of > the parts (master, transaction, report) is using form (form to input, or > edit master. form to input transaction. form to generate report and show > the table query result). > the problem is when not using cache, the apps respond is slow (function to > calculate and table record callback), any idea the best way how to > implement it using web2py way? > Forms include a unique _formkey hidden field, so you shouldn't cache pages that include forms. If a page simply includes some data, it's fine to cache as long as there is no issue of "freshness" (i.e., if the data are changing constantly, caching for a long time will end up serving stale data). Whether caching makes sense is up to you -- it's a trade-off between speed and freshness. 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.

