Changeset 3339 in products


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

caching of the dropdownmenu revisited

Location:
quintagroup.dropdownmenu/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.dropdownmenu/trunk/docs/CONTRIBUTORS.txt

    r2844 r3339  
    77Olha Pelishok   [olha] 
    88Taras Melnychuk [fenix] 
     9Malthe Borch 
  • quintagroup.dropdownmenu/trunk/docs/HISTORY.txt

    r3287 r3339  
    11Changelog 
    22========= 
     3 
     41.2.6 - Jan 26, 2012 
     5 
     6* revisited caching key strategies, added language and anonymous switch  
     7* added caching switch to control panel 
    38 
    491.2.5 - Oct 21, 2011 
  • 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): 
  • quintagroup.dropdownmenu/trunk/quintagroup/dropdownmenu/interfaces.py

    r3151 r3339  
    44 
    55from plone.theme.interfaces import IDefaultPloneLayer 
     6from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm 
    67 
    78from quintagroup.dropdownmenu import _ 
    89 
     10cachings = SimpleVocabulary( 
     11    [SimpleTerm(value=u'anonymous', title=_(u'Cache only for anonymous')), 
     12     SimpleTerm(value=u'all', title=_(u'Cache for all users')),] 
     13    ) 
    914 
    1015class IDropDownMenuLayer(IDefaultPloneLayer): 
     
    7883        default=u"_sub", 
    7984        required=False) 
     85     
     86    enable_caching = schema.Bool( 
     87        title=_(u"Enable menu caching"), 
     88        description=_(u"Caching of the menu viewlet improves page rendering " 
     89                      u"speed."), 
     90        default=True         
     91        ) 
     92 
     93    caching_strategy = schema.Choice( 
     94    title=_(u"Select caching strategy"), 
     95    description=_(u"Caching strategy defines how the cache key will be built."), 
     96    default="anonymous", 
     97    vocabulary=cachings         
     98    ) 
  • quintagroup.dropdownmenu/trunk/setup.py

    r3287 r3339  
    22import os 
    33 
    4 version = '1.2.5' 
     4version = '1.2.6' 
    55 
    66tests_require = ['zope.testing', 
     
    1515        "Framework :: Plone", 
    1616        "Programming Language :: Python", 
     17        "License :: OSI Approved :: GNU General Public License (GPL)", 
     18        "Operating System :: OS Independent" 
    1719        "Topic :: Software Development :: Libraries :: Python Modules", 
    1820        ], 
Note: See TracChangeset for help on using the changeset viewer.