Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8423495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:44:18+00:00 2026-06-10T03:44:18+00:00

plone.memoize packages provides handy helper functions for caching values of various functions. What is

  • 0

plone.memoize packages provides handy helper functions for caching values of various functions.

What is the best practice of caching values of view/viewlet methods for the lifetime of the current HTTP Request (self.request). This is not entirely clear from plone.memoize documentation.

Example:

   class MyView(grok.View):

         # cache this by self.request
         def getExpensiveFunction(self):
               ....
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T03:44:19+00:00Added an answer on June 10, 2026 at 3:44 am

    Since a BrowserPage view instance’s lifetime is normally the duration of the request already, you generally may just as well use the plone.memoize.instance memoizing decorator:

    from plone.memoize.instance import memoize
    
    class MyView(grok.View):
    
        @memoize
        def getExpensiveFunction(self):
            # ....
    

    After all, the BrowserPage is normally looked up for a given URL, instanciated when looked up, and discarded when the view has been produced. A new request will produce a new instance.

    The view memoizer stores the cache on the current request, and adds the current context path (or the id of the context, if there is no path) as a cache key. If the view is looked up in different places during a request you can use that instead of the instance memoizer:

    from plone.memoize.view import memoize
    
    class MyView(grok.View):
    
        @memoize
        def getExpensiveFunction(self):
            # ....
    

    Utility views, like @@plone_context and such, benefit most from plone.memoize.view.memoize.

    If your expensive method is independent of the view context, use the memoize_contextless decorator; this omits the view context path from the cache key:

    from plone.memoize.view import memoize_contextless
    
    class MyView(grok.View):
    
        @memoize_contextless
        def getExpensiveFunction(self):
            # ....
    

    So, if .getExpensiveFunction() would return the same information regardless of what the context of this view is (be it the site root or somewhere deep in the content tree), use the _contextless variant so you store only one copy of the result.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Plone's viewlets appear to be site-wide by default. How can I make a viewlet
I'd like to Plone load Javascripts only for a specific view. I really really
In Plone adding a member variable in a view class instance automatically makes it
We are using Plone 4.1, and would like to have a custom view of
$ pip install Plone installed a lot of packages but then aborted with this
The Portlets in Plone are quite handy but I'd like to be able to
Plone's base setup profile -- in Products.CMFPlone.setuphandlers.setupPortalContent() -- queries for a registered view named
plone.resource provides simple way to drop in static media files in your Plone http://pypi.python.org/pypi/plone.resource
Plone has a neat categorization feature of content using tags and a tag cloub.
I have configured Plone with the following buildout (via http://build.pythonpackages.com/buildout/plone/4.2.x ): [buildout] allow-hosts =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.