Ignore:
Timestamp:
Jan 26, 2012 2:50:56 PM (12 years ago)
Author:
chervol
Message:

caching of the dropdownmenu revisited

File:
1 edited

Legend:

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

    r3240 r3339  
    2323import copy 
    2424 
    25  
    2625def menu_cache_key(f, view): 
     26    # menu cache key conssits of: 
     27    # - selected item not only top tab 
     28    # - site can beaccessed on different domains  
     29    # - language is important for multilingua sites 
     30 
    2731    portal_state = getMultiAdapter((view.context, view.request), 
    2832                                   name=u'plone_portal_state') 
     
    3135    if view.conf.content_tabs_level > 0: 
    3236        content_path = content_path[:view.conf.content_tabs_level] 
    33     path_key = '/'.join(content_path) 
     37    path_key = view.request.physicalPathToURL(content_path) 
     38 
     39    language = portal_state.locale().getLocaleID() 
     40 
     41    # Cache for five minutes. Note that the HTTP RAM-cache 
     42    # typically purges entries after 60 minutes. 
    3443    return view.__name__ + \ 
    3544           path_key + \ 
    36            str(time() // (60 * 5))  # Every five minutes 
    37                                     # Note that the HTTP RAM-cache 
    38                                     # typically purges entries after 
    39                                     # 60 minutes. 
    40  
    41  
     45           language + \ 
     46           str(time() // (60 * 5))   
     47 
     48# we are gcaching the menu structure built out of portal_actions tool 
     49# this cache key does not take in account expressions and roles settings 
    4250def tabs_cache_key(f, view, site_url): 
    4351    return site_url + str(time() // (60 * 60)) 
    4452 
    45  
    4653def dropdowncache(f): 
    4754    def func(view): 
    48         if view.conf.show_actions_tabs: 
     55        portal_state = getMultiAdapter((view.context, view.request), 
     56                                        name=u'plone_portal_state') 
     57        # it is impossible to reliably cache entire rendered menu generated   
     58        # with potral actions strategy. 
     59        if not view.conf.enable_caching or view.conf.show_actions_tabs or \ 
     60           (not portal_state.anonymous() and \ 
     61                view.conf.caching_strategy == 'anonymous'): 
    4962            return f(view) 
    5063        return ram.cache(menu_cache_key)(f)(view) 
     
    5568    index = ViewPageTemplateFile('templates/sections.pt') 
    5669    recurse = ViewPageTemplateFile('templates/sections_recurse.pt') 
     70 
    5771 
    5872    def update(self): 
Note: See TracChangeset for help on using the changeset viewer.