@cache lose response

26 views
Skip to first unread message

Dmitry Ermolaev

unread,
Jul 8, 2015, 1:59:19 AM7/8/15
to web...@googlegroups.com
if
@cache.action(time_expire=exp_time, cache_model=cache.disk, vars=False, public=False, lang=True)
def contacts():
    response.title=T('Контакты')
    response.not_show_func = True
    h = CAT(
        H3(T('Отзывы, Обсуждение, Жалобы, Благодарности')),
        T('Можно найти в ветке на'),' ',
        A(T('международном форуме о криптовалютах'),
          _href='https://bitcointalk.org/index.php?topic=307648.0', _target='_blank'),'. ',
        T('Там же можно сообщить об ошибке'),'.',
        H3('Обратная связь'),
        T('Почтовый ящик'),': ', 'sup...@7Pay.in',BR(),
        T('Skype'),': ', 'i-creator'
    )
    return dict(h =h)


If 1-st call - al ok!
then - view run as response.title and response not_show_func is null
view is generic:
{{extend 'layout.html'}}

{{if not response.not_show_func:}}
<h2>{{=' '.join(x.capitalize() for x in request.function.split('_'))}}</h2>
{{pass}}
{{if len(response._vars)==1:}}
{{=BEAUTIFY(response._vars.values()[0])}}
{{elif len(response._vars)>1:}}
{{=BEAUTIFY(response._vars)}}
{{pass}}
{{if request.is_local:}}
{{=response.toolbar()}}
{{pass}}



Message has been deleted

Dmitry Ermolaev

unread,
Jul 8, 2015, 2:21:10 AM7/8/15
to web...@googlegroups.com
exp_time = request.is_local and 3 or 360
@cache(request.env.path_info, time_expire=exp_time)

not work properly - 1st call if good but all other calls is bad with response.any_my_vars is null

Anthony

unread,
Jul 8, 2015, 10:54:19 AM7/8/15
to web...@googlegroups.com, eds....@gmail.com
Caching an action in a controller only caches the value returned by the action itself (i.e., the dictionary returned at the end of the function). It does not cache the response object or any of its attributes, so response.title, etc. will not be cached. If you want to cache the final HTML response that is sent to the browser, then you must call response.render() inside the action. This is explained here: http://web2py.com/books/default/chapter/29/04/the-core#cache.

Anthony

Dmitry Ermolaev

unread,
Jul 8, 2015, 12:43:23 PM7/8/15
to web...@googlegroups.com, eds....@gmail.com
@cache.action(time_expire=300, cache_model=cache.ram, quick='SVP')
it not use response.vars ? why?

why I cant store title in cache?
def contacts():
    response.title=T('some title')
...


среда, 8 июля 2015 г., 17:54:19 UTC+3 пользователь Anthony написал:

Anthony

unread,
Jul 8, 2015, 2:17:47 PM7/8/15
to web...@googlegroups.com, eds....@gmail.com
On Wednesday, July 8, 2015 at 12:43:23 PM UTC-4, Dmitry Ermolaev wrote:
@cache.action(time_expire=300, cache_model=cache.ram, quick='SVP')
it not use response.vars ? why?

There is request.vars but no response.vars.
 
why I cant store title in cache?
def contacts():
    response.title=T('some title')

You can cache anything you want. However, the @cache decorator only caches the value returned by the function it is decorating. Notice that your function does not return the value of response.title -- it merely sets the value of response.title. If you want that value cached, then you have to return it from the function. Alternatively, rather than having your function return a dictionary (which is what will get cached) and then execute the view, you can have your function call response.render() in order to execute the view itself. The function can then return the rendered view (which is really just an HTML string value), which is what will get cached.

Anthony
Reply all
Reply to author
Forward
0 new messages