Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes
plone.memoize.view.ViewMemo Class Reference
Collaboration diagram for plone.memoize.view.ViewMemo:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def memoize
def memoize_contextless

Static Public Attributes

string key = 'plone.memoize'

Detailed Description

Definition at line 17 of file view.py.


Member Function Documentation

def plone.memoize.view.ViewMemo.memoize (   self,
  func 
)

Definition at line 21 of file view.py.

00021 
00022     def memoize(self, func):
00023         def memogetter(*args, **kwargs):
00024             instance = args[0]
00025             
00026             context = getattr(instance, 'context', None)            
00027             request = getattr(instance, 'request', None)
00028             
00029             # XXX: A Zope 2 workaround/optimisation (will degrade gracefully)
00030             if request is None:
00031                 request = getattr(context, 'REQUEST', None)
00032             
00033             annotations = IAnnotations(request)
00034             cache = annotations.get(self.key, _marker)
00035             
00036             if cache is _marker:
00037                 cache = annotations[self.key] = dict()
00038                 
00039             # XXX: Not the most elegant thing in the world; in a Zope 2
00040             # context, the physical path is a better key, since the id could
00041             # change if the object is invalidated from the ZODB cache
00042             
00043             try:
00044                 context_id = context.getPhysicalPath()
00045             except AttributeError:
00046                 context_id = id(context)
00047             
00048             # Note: we don't use args[0] in the cache key, since args[0] == 
00049             # instance and the whole point is that we can cache different
00050             # requests
00051             
00052             key = (context_id, instance.__class__.__name__, func.__name__, 
00053                    args[1:], frozenset(kwargs.items()))
00054             value = cache.get(key, _marker)
00055             if value is _marker:
00056                 value = cache[key] = func(*args, **kwargs)
00057             return value
00058         return memogetter

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 59 of file view.py.

00059 
00060     def memoize_contextless(self, func):
00061         def memogetter(*args, **kwargs):
00062             instance = args[0]
00063             request = getattr(instance, 'request', None)
00064             
00065             annotations = IAnnotations(request)
00066             cache = annotations.get(self.key, _marker)
00067             
00068             if cache is _marker:
00069                 cache = annotations[self.key] = dict()
00070             
00071             key = (instance.__class__.__name__, func.__name__, 
00072                    args[1:], frozenset(kwargs.items()))
00073             value = cache.get(key, _marker)
00074             if value is _marker:
00075                 value = cache[key] = func(*args, **kwargs)
00076             return value
00077         return memogetter

Here is the call graph for this function:


Member Data Documentation

string plone.memoize.view.ViewMemo.key = 'plone.memoize' [static]

Definition at line 19 of file view.py.


The documentation for this class was generated from the following file: