Changeset 3234 in products


Ignore:
Timestamp:
Jun 10, 2011 11:20:25 AM (13 years ago)
Author:
kroman0
Message:

Apply Malthes caching patch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.dropdownmenu/trunk/quintagroup/dropdownmenu/browser/viewlets.py

    r3153 r3234  
    1111 
    1212from plone.memoize.instance import memoize 
     13from plone.memoize.compress import xhtmlslimmer 
    1314from plone.app.layout.viewlets import common 
    1415from plone.app.layout.navigation.navtree import buildFolderTree 
     
    2223import copy 
    2324 
    24  
    25 def cache_key(a, b, c): 
    26     return c + str(time() // (60 * 60)) 
     25def menu_cache_key(f, view): 
     26    try: 
     27        section = view.context.getPhysicalPath()[2] 
     28    except: 
     29        section = "" 
     30 
     31    return view.__name__ + \ 
     32           section + \ 
     33           str(time() // (60 * 5))  # Every five minutes 
     34                                    # Note that the HTTP RAM-cache 
     35                                    # typically purges entries after 
     36                                    # 60 minutes. 
     37 
     38 
     39def tabs_cache_key(f, view, site_url): 
     40    return site_url + str(time() // (60 * 60)) 
    2741 
    2842 
     
    3650 
    3751        # prepare to gather portal tabs 
    38         tabs = [] 
    3952        context = aq_inner(self.context) 
    4053        self.conf = conf = self._settings() 
     
    4962        self.cat_sufix = self.conf.nested_category_sufix or '' 
    5063        self.cat_prefix = self.conf.nested_category_prefix or '' 
     64 
     65    @property 
     66    def portal_tabs(self): 
     67        tabs = [] 
     68 
    5169        # fetch actions-based tabs? 
    52         if conf.show_actions_tabs: 
     70        if self.conf.show_actions_tabs: 
    5371            tabs.extend(self._actions_tabs()) 
    5472 
    5573        # fetch content structure-based tabs? 
    56         if conf.show_content_tabs: 
     74        if self.conf.show_content_tabs: 
    5775            # put content-based actions before content structure-based ones? 
    58             if conf.content_before_actions_tabs: 
     76            if self.conf.content_before_actions_tabs: 
    5977                tabs = self._content_tabs() + tabs 
    6078            else: 
    6179                tabs.extend(self._content_tabs()) 
    6280 
    63         # assign collected tabs eventually 
    64         self.portal_tabs = tabs 
     81        return tabs 
    6582 
    6683    def _actions_tabs(self): 
     
    101118        return res 
    102119 
    103     @ram.cache(cache_key) 
     120    @ram.cache(tabs_cache_key) 
    104121    def prepare_tabs(self, site_url): 
    105122        def normalize_actions(category, object, level, parent_url=None): 
     
    203220        return getDropDownMenuSettings(self.context) 
    204221 
     222    @ram.cache(menu_cache_key) 
    205223    def createMenu(self): 
    206         return self.recurse(children=self.portal_tabs, level=1) 
     224        html = self.recurse(children=self.portal_tabs, level=1) 
     225        return xhtmlslimmer.compress(html) 
    207226 
    208227    def _old_update(self): 
Note: See TracChangeset for help on using the changeset viewer.