i have a set of nested menu options that pretty heavy on the database. They only actually change on a nightly update to the server so i thought i would chache them. I need to have them passed into each controller method since they need to pass to my master template.
looking here http://turbogears.readthedocs.org/en/latest/turbogears/caching.html?highlight=caching I came up with... def _before(self, *args, **kw): def get_item_cats(): return model.DBSession.query(model.m_items.ItemCategory).order_by(model.m_items.ItemCategory.id) def get_ie_class(): result = re.search(";\s*(MSIE\s)*(\d)", request.user_agent) # Match is_ie, ie_class = False, '' if result: is_ie = int(result.group(2)) ie_class = 'no-js ie%s oldie' %is_ie return (is_ie, ie_class) mycache_cats = cache.get_cache('get_item_cats') cachedvalue_cats = mycache_cats.get_value( key=datetime.date.month, createfunc=get_item_cats, expiretime=3600 ) tmpl_context.extra_flags = {'show_admin':False} tmpl_context.is_ie,tmpl_context.ie_class = get_ie_class()[:] tmpl_context.item_cats = cachedvalue_cats then i have to include tmpl_context in each controller method and put the def _before in every controller that I create. Is there a better cleaner way to do this so that i don't have to manually add tmpl_context to the dictionary on every controller and is there a better way to include this in all controllers? Thanks! -- You received this message because you are subscribed to the Google Groups "TurboGears" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/turbogears. For more options, visit https://groups.google.com/groups/opt_out.

