> > *Controller* > > def getcostdata(): > db.executesql (*get data on costs, for example*) > transform data > plotting library internals > > *View* > view data using plot library/html > > Questions: > 1. Should I use session variable and retrieve data from a dictionary - > build some kind of cache (that expires at a certain interval) so multiple > views won't run the same query multiple times needlessly? >
Sure, but keep in mind the session is for a single user. If you want to share the results of a query across multiple users, use the cache instead. > 2. I've seen some people say that functions like this should be placed > inside a model or a module? Is there a difference in performance : > controller vs. model vs. module? > Not sure what you mean by "functions like this." Controller actions should be used for the purpose of generating responses to HTTP requests at a particular URL. If you have a function that needs to be used more generally, move it to a model or module and call it from a controller or wherever else it is needed. Putting functions in modules (rather than model files) will be a little more efficient (no need to redefine on every request), but probably not too big a deal, particularly for just a few small functions. > 3. I would like to reuse the information from a function in another place > in my app but not load it needlessly -> module? > Sure. > 4. How can call a function from another controller ? > Depends what you mean. If you want to make a direct function call, put the function in a model or module and call it from whichever controllers need it. Alternatively, you could make an internal HTTP request to the URL of the other controller, but that's probably not what you're looking to do. 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.