On Sunday, February 25, 2018 at 7:26:52 PM UTC-5, 黄祥 wrote:
>
> pardon, is this function is cached? on which side database, views, or 
> function?
> *modules/test_report.py*
> @cache.action(time_expire = cache_time_expire, cache_model = cache_model, 
> quick = cache_quick, prefix = cache_prefix) *# cache function, isn't it?*
>

Yes, this caches the output of a function. Note, though, that 
@cache.action() is specifically intended for actions in controllers because 
it also sets response headers that tell the browser to cache the HTML page 
for some time.
 

> def report_0(cache_db, print_controller):
> rows_currency = db(db.currency.id > 0).*iterselect*(cache = cache_db, 
> cacheable = True) *# cache query result, isn't it?*
>

I believe the "cache" argument is simply ignored with .iterselect(), as it 
doesn't make sense to cache the query result in this case (because 
.iterselect() does not retrieve all the records at once). If you want to 
cache the entire result set so you do not have to repeat the query, then 
use .select().
 

> d = dict(rows_currency = rows_currency, print_controller = 
> print_controller)
> return response.render(d) *# cache view, isn't it? not sure bout this 
> one, because it will contain another nested loop in the views part*
>

response.render() will return the final generated HTML (note, it is not 
caching the "view", which technically is the web2py template code -- it is 
caching the *result of executing the view*, which is just HTML). So, if the 
function returns that, then yes, the final HTML of the page is being 
cached. Any loops in the view are executed along with the view code, and 
the final output is cached.
 

> in my previous posted i cut the views part because it contain the nested 
> loop of the result of rows_currency e.g.
>

There is no reason to avoid caching the final HTML unless there are 
elements within the view code that generate data you don't want to cache 
from request to request. Loops are not a problem.
 

> is iterselect result is not cached while the select result is cached?
>

Correct.
 

> the reason i use iterselect is faster than select, pls correct me if i'm 
> wrong
>

If you cache the output of the function and the function returns 
response.render(), then that is all you need to cache. In that case, there 
is no need to also cache the select because on subsequent requests, the 
function itself won't even be run, as the cache system will return the 
cached output of the function rather than running the function itself. So, 
go ahead and use .iterselect() and just return response.render().

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.

Reply via email to