Exemplo n.º 1
0
 def func(view):
     portal_state = getMultiAdapter((view.context, view.request),
                                    name=u'plone_portal_state')
     # it is impossible to reliably cache entire rendered menu generated
     # with potral actions strategy.
     if not view.conf.enable_caching or view.conf.show_actions_tabs or \
         (not portal_state.anonymous() and
             view.conf.caching_strategy == 'anonymous'):
         return f(view)
     return ram.cache(menu_cache_key)(f)(view)
Exemplo n.º 2
0
def soap_cache(wrapped):

    def get_cache_key(method, self, id_or_path, *args, **kwargs):
        return '#'.join((
                self._settings.UID(),
                self._repository_id,
                id_or_path.encode('ascii', 'xmlcharrefreplace'),
                str(time.time() // (self._settings.repository_cache * 60))))

    return ram.cache(get_cache_key)(wrapped)
Exemplo n.º 3
0
 def func(view):
     portal_state = getMultiAdapter((view.context, view.request),
                                    name=u'plone_portal_state')
     # it is impossible to reliably cache entire rendered menu generated
     # with potral actions strategy.
     if not view.conf.enable_caching or view.conf.show_actions_tabs or \
         (not portal_state.anonymous() and
             view.conf.caching_strategy == 'anonymous'):
         return f(view)
     return ram.cache(menu_cache_key)(f)(view)
Exemplo n.º 4
0
 def func(view, site_url):
     if not view.conf.enable_caching:
         return f(view, site_url)
     return ram.cache(tabs_cache_key)(f)(view, site_url)
Exemplo n.º 5
0
class Renderer(base.Renderer):
    _template = ViewPageTemplateFile('recent.pt')

    title = _('box_recent_changes', default=u"Recent Changes")

    def __init__(self, *args):
        base.Renderer.__init__(self, *args)

        context = aq_inner(self.context)
        portal_state = getMultiAdapter(
            (context, self.request), name='plone_portal_state')
        self.anonymous = portal_state.anonymous()
        self.navigation_root_url = portal_state.navigation_root_url()
        self.typesToShow = portal_state.friendly_types()
        self.navigation_root_path = portal_state.navigation_root_path()

        plone_tools = getMultiAdapter(
            (context, self.request), name='plone_tools')
        self.catalog = plone_tools.catalog()

    ram.cache(_render_cachekey)
    def render(self):
        return xhtml_compress(self._template())

    @property
    def available(self):
        return not self.anonymous and self.data.count > 0 and len(self._data())

    def recent_items(self):
        return self._data()

    def recently_modified_link(self):
        return '%s/recently_modified' % self.navigation_root_url

    @memoize
    def _data(self):
        limit = self.data.count
        path = self.navigation_root_path
        return self.catalog(portal_type=self.typesToShow,
                            path=path,
                            sort_on='modified',
                            sort_order='reverse',
                            sort_limit=limit)[:limit]

    @memoize
    def thumb_scale(self):
        """Use override value or read thumb_scale from registry.
        Image sizes must fit to value in allowed image sizes.
        None will suppress thumb.
        """
        if getattr(self.data, 'no_thumbs', False):
            # Individual setting overrides ...
            return None
        thsize = getattr(self.data, 'thumb_scale', None)
        if thsize:
            return thsize
        registry = getUtility(IRegistry)
        settings = registry.forInterface(
            ISiteSchema, prefix="plone", check=False)
        thumb_scale_portlet = settings.thumb_scale_portlet
        return thumb_scale_portlet

    def getMimeTypeIcon(self, obj):
        fileo = obj.getObject().file
        portal_url = getNavigationRoot(self.context)
        mtt = getToolByName(self.context, 'mimetypes_registry')
        if fileo.contentType:
            ctype = mtt.lookup(fileo.contentType)
            return os.path.join(
                portal_url,
                guess_icon_path(ctype[0])
            )
        return None
Exemplo n.º 6
0
 def func(url, api_key=None):
     if get_embedly_settings('persistent_cache'):
         return _m.memoize(f)(url, api_key)
     return ram.cache(get_oembed_cache_key)(f)(url, api_key)
Exemplo n.º 7
0
 def func(url, api_key=None):
     if get_embedly_settings('persistent_cache'):
         return _m.memoize(f)(url, api_key)
     return ram.cache(get_oembed_cache_key)(f)(url, api_key)
Exemplo n.º 8
0
 def cache(get_key):
     return ram.cache(get_key)
def cache_user(method):

    def get_cache_key(method, self, user):
        return '#'.join((user.getId() or '', str(time.time() // (5 * 60 * 60))))

    return ram.cache(get_cache_key)(method)
Exemplo n.º 10
0
 def func(view):
     if view.conf.show_actions_tabs:
         return f(view)
     return ram.cache(menu_cache_key)(f)(view)
Exemplo n.º 11
0
 def func(view, site_url):
     if not view.conf.enable_caching:
         return f(view, site_url)
     return ram.cache(tabs_cache_key)(f)(view, site_url)
Exemplo n.º 12
0
 def cache(get_key):
     return ram.cache(get_key)
Exemplo n.º 13
0
def cache_user(method):
    def get_cache_key(method, self, user):
        return '#'.join((user.getId()
                         or '', str(time.time() // (5 * 60 * 60))))

    return ram.cache(get_cache_key)(method)