Back to index

plone3  3.1.7
Public Member Functions | Private Attributes
CMFCore.CachingPolicyManager.CachingPolicy Class Reference

List of all members.

Public Member Functions

def __init__
def getPolicyId
def getPredicate
def getMTimeFunc
def getMaxAgeSecs
def getSMaxAgeSecs
def getNoCache
def getNoStore
def getMustRevalidate
def getProxyRevalidate
def getPublic
def getPrivate
def getNoTransform
def getVary
def getETagFunc
def getEnable304s
def getLastModified
def getPreCheck
def getPostCheck
def testPredicate
def getHeaders

Private Attributes

 _policy_id
 _predicate
 _mtime_func
 _max_age_secs
 _s_max_age_secs
 _no_cache
 _no_store
 _must_revalidate
 _proxy_revalidate
 _public
 _private
 _no_transform
 _vary
 _etag_func
 _enable_304s
 _last_modified
 _pre_check
 _post_check

Detailed Description

    Represent a single class of cachable objects:

      - class membership is defined by 'predicate', a TALES expression
        with access to the following top-level names:

        'object' -- the object itself

        'view' -- the name of the view method

        'keywords' -- keywords passed to the request

        'request' -- the REQUEST object itself

        'member' -- the authenticated member, or None if anonymous

        'modules' -- usual TALES access-with-import

        'nothing' -- None

        'time' -- A DateTime object for the current date and time

      - mtime_func is used to set the "Last-modified" HTTP response
        header, which is another TALES expression evaluated
        against the same namespace.  If not specified explicitly,
        uses 'object/modified'.  mtime_func is also used in responding
        to conditional GETs.

      - The "Expires" HTTP response header and the "max-age" token of
        the "Cache-control" header will be set using 'max_age_secs',
        if passed;  it should be an integer value in seconds.

      - The "s-maxage" token of the "Cache-control" header will be
        set using 's_max_age_secs', if passed;  it should be an integer
        value in seconds.

      - The "Vary" HTTP response headers will be set if a value is 
        provided. The Vary header is described in RFC 2616. In essence,
        it instructs caches that respect this header (such as Squid
        after version 2.4) to distinguish between requests not just by
        the request URL, but also by values found in the headers showing
        in the Vary tag. "Vary: Cookie" would force Squid to also take 
        Cookie headers into account when deciding what cached object to 
        choose and serve in response to a request.

      - The "ETag" HTTP response header will be set if a value is
        provided. The value is a TALES expression and the result 
        after evaluation will be used as the ETag header value.

      - Other tokens will be added to the "Cache-control" HTTP response
        header as follows:

         'no_cache=1' argument => "no-cache" token

         'no_store=1' argument => "no-store" token

         'must_revalidate=1' argument => "must-revalidate" token

         'proxy_revalidate=1' argument => "proxy-revalidate" token

         'public=1' argument => "public" token

         'private=1' argument => "private" token

         'no_transform=1' argument => "no-transform" token

      - The last_modified argument is used to determine whether to add a
        Last-Modified header.  last_modified=1 by default.  There appears
        to be a bug in IE 6 (and possibly other versions) that uses the
        Last-Modified header plus some heuristics rather than the other
        explicit caching headers to determine whether to render content
        from the cache.  If you set, say, max-age=0, must-revalidate and
        have a Last-Modified header some time in the past, IE will
        recognize that the page in cache is stale and will request an
        update from the server BUT if you have a Last-Modified header
        with an older date, will then ignore the update and render from
        the cache, so you may want to disable the Last-Modified header
        when controlling caching using Cache-Control headers.

      - The pre-check and post-check Cache-Control tokens are Microsoft
        proprietary tokens added to IE 5+.  Documentation can be found
        here: http://msdn.microsoft.com/workshop/author/perf/perftips.asp
        Unfortunately these are needed to make IE behave correctly.

Definition at line 125 of file CachingPolicyManager.py.


Constructor & Destructor Documentation

def CMFCore.CachingPolicyManager.CachingPolicy.__init__ (   self,
  policy_id,
  predicate = '',
  mtime_func = '',
  max_age_secs = None,
  no_cache = 0,
  no_store = 0,
  must_revalidate = 0,
  vary = '',
  etag_func = '',
  s_max_age_secs = None,
  proxy_revalidate = 0,
  public = 0,
  private = 0,
  no_transform = 0,
  enable_304s = 0,
  last_modified = 1,
  pre_check = None,
  post_check = None 
)

Definition at line 233 of file CachingPolicyManager.py.

00233 
00234                 ):
00235 
00236         if not predicate:
00237             predicate = 'python:1'
00238 
00239         if not mtime_func:
00240             mtime_func = 'object/modified'
00241 
00242         if max_age_secs is not None:
00243             if str(max_age_secs).strip() == '':
00244                 max_age_secs = None
00245             else:
00246                 max_age_secs = int( max_age_secs )
00247 
00248         if s_max_age_secs is not None:
00249             if str(s_max_age_secs).strip() == '':
00250                 s_max_age_secs = None
00251             else:
00252                 s_max_age_secs = int( s_max_age_secs )
00253 
00254         if pre_check is not None:
00255             if str(pre_check).strip() == '':
00256                 pre_check = None
00257             else:
00258                 pre_check = int(pre_check)
00259 
00260         if post_check is not None:
00261             if str(post_check).strip() == '':
00262                 post_check = None
00263             else:
00264                 post_check = int(post_check)
00265 
00266         self._policy_id = policy_id
00267         self._predicate = Expression( text=predicate )
00268         self._mtime_func = Expression( text=mtime_func )
00269         self._max_age_secs = max_age_secs
00270         self._s_max_age_secs = s_max_age_secs
00271         self._no_cache = int( no_cache )
00272         self._no_store = int( no_store )
00273         self._must_revalidate = int( must_revalidate )
00274         self._proxy_revalidate = int( proxy_revalidate )
00275         self._public = int( public )
00276         self._private = int( private )
00277         self._no_transform = int( no_transform )
00278         self._vary = vary
00279         self._etag_func = Expression( text=etag_func )
00280         self._enable_304s = int ( enable_304s )
00281         self._last_modified = int( last_modified )
00282         self._pre_check = pre_check
00283         self._post_check = post_check

Here is the call graph for this function:


Member Function Documentation

Definition at line 360 of file CachingPolicyManager.py.

00360 
00361     def getEnable304s(self):
00362         """
00363         """
00364         return getattr(self, '_enable_304s', 0)

Definition at line 349 of file CachingPolicyManager.py.

00349 
00350     def getETagFunc( self ):
00351         """
00352         """
00353         etag_func_text = ''
00354         etag_func = getattr(self, '_etag_func', None)
00355 
00356         if etag_func is not None:
00357             etag_func_text = etag_func.text
00358 
00359         return etag_func_text

Here is the caller graph for this function:

def CMFCore.CachingPolicyManager.CachingPolicy.getHeaders (   self,
  expr_context 
)
    Does this request match our predicate?  If so, return a
    sequence of caching headers as ( key, value ) tuples.
    Otherwise, return an empty sequence.

Definition at line 383 of file CachingPolicyManager.py.

00383 
00384     def getHeaders( self, expr_context ):
00385         """
00386             Does this request match our predicate?  If so, return a
00387             sequence of caching headers as ( key, value ) tuples.
00388             Otherwise, return an empty sequence.
00389         """
00390         headers = []
00391 
00392         if self.testPredicate( expr_context ):
00393 
00394             if self.getLastModified():
00395                 mtime = self._mtime_func( expr_context )
00396                 if type( mtime ) is type( '' ):
00397                     mtime = DateTime( mtime )
00398                 if mtime is not None:
00399                     mtime_str = rfc1123_date(mtime.timeTime())
00400                     headers.append( ( 'Last-modified', mtime_str ) )
00401 
00402             control = []
00403 
00404             if self.getMaxAgeSecs() is not None:
00405                 now = expr_context.vars[ 'time' ]
00406                 exp_time_str = rfc1123_date(now.timeTime() + self._max_age_secs)
00407                 headers.append( ( 'Expires', exp_time_str ) )
00408                 control.append( 'max-age=%d' % self._max_age_secs )
00409 
00410             if self.getSMaxAgeSecs() is not None:
00411                 control.append( 's-maxage=%d' % self._s_max_age_secs )
00412 
00413             if self.getNoCache():
00414                 control.append( 'no-cache' )
00415                 # The following is for HTTP 1.0 clients
00416                 headers.append(('Pragma', 'no-cache'))
00417 
00418             if self.getNoStore():
00419                 control.append( 'no-store' )
00420 
00421             if self.getPublic():
00422                 control.append( 'public' )
00423 
00424             if self.getPrivate():
00425                 control.append( 'private' )
00426 
00427             if self.getMustRevalidate():
00428                 control.append( 'must-revalidate' )
00429 
00430             if self.getProxyRevalidate():
00431                 control.append( 'proxy-revalidate' )
00432 
00433             if self.getNoTransform():
00434                 control.append( 'no-transform' )
00435 
00436             pre_check = self.getPreCheck()
00437             if pre_check is not None:
00438                 control.append('pre-check=%d' % pre_check)
00439 
00440             post_check = self.getPostCheck()
00441             if post_check is not None:
00442                 control.append('post-check=%d' % post_check)
00443 
00444             if control:
00445                 headers.append( ( 'Cache-control', ', '.join( control ) ) )
00446 
00447             if self.getVary():
00448                 headers.append( ( 'Vary', self._vary ) )
00449 
00450             if self.getETagFunc():
00451                 headers.append( ( 'ETag', self._etag_func( expr_context ) ) )
00452 
00453         return headers
00454 
00455 

Here is the call graph for this function:

Should we set the last modified header?

Definition at line 365 of file CachingPolicyManager.py.

00365 
00366     def getLastModified(self):
00367         """Should we set the last modified header?"""
00368         return getattr(self, '_last_modified', 1)

Here is the caller graph for this function:

Definition at line 299 of file CachingPolicyManager.py.

00299 
00300     def getMaxAgeSecs( self ):
00301         """
00302         """
00303         return self._max_age_secs

Here is the caller graph for this function:

Definition at line 294 of file CachingPolicyManager.py.

00294 
00295     def getMTimeFunc( self ):
00296         """
00297         """
00298         return self._mtime_func.text

Definition at line 319 of file CachingPolicyManager.py.

00319 
00320     def getMustRevalidate( self ):
00321         """
00322         """
00323         return self._must_revalidate

Here is the caller graph for this function:

Definition at line 309 of file CachingPolicyManager.py.

00309 
00310     def getNoCache( self ):
00311         """
00312         """
00313         return self._no_cache

Here is the caller graph for this function:

Definition at line 314 of file CachingPolicyManager.py.

00314 
00315     def getNoStore( self ):
00316         """
00317         """
00318         return self._no_store

Here is the caller graph for this function:

Definition at line 339 of file CachingPolicyManager.py.

00339 
00340     def getNoTransform( self ):
00341         """
00342         """
00343         return getattr(self, '_no_transform', 0)

Here is the caller graph for this function:

Definition at line 284 of file CachingPolicyManager.py.

00284 
00285     def getPolicyId( self ):
00286         """
00287         """
00288         return self._policy_id

Definition at line 374 of file CachingPolicyManager.py.

00374 
00375     def getPostCheck(self):
00376         """
00377         """
00378         return getattr(self, '_post_check', None)

Here is the caller graph for this function:

Definition at line 369 of file CachingPolicyManager.py.

00369 
00370     def getPreCheck(self):
00371         """
00372         """
00373         return getattr(self, '_pre_check', None)

Here is the caller graph for this function:

Definition at line 289 of file CachingPolicyManager.py.

00289 
00290     def getPredicate( self ):
00291         """
00292         """
00293         return self._predicate.text

Definition at line 334 of file CachingPolicyManager.py.

00334 
00335     def getPrivate( self ):
00336         """
00337         """
00338         return getattr(self, '_private', 0)

Here is the caller graph for this function:

Definition at line 324 of file CachingPolicyManager.py.

00324 
00325     def getProxyRevalidate( self ):
00326         """
00327         """
00328         return getattr(self, '_proxy_revalidate', 0)

Here is the caller graph for this function:

Definition at line 329 of file CachingPolicyManager.py.

00329 
00330     def getPublic( self ):
00331         """
00332         """
00333         return getattr(self, '_public', 0)

Here is the caller graph for this function:

Definition at line 304 of file CachingPolicyManager.py.

00304 
00305     def getSMaxAgeSecs( self ):
00306         """
00307         """
00308         return getattr(self, '_s_max_age_secs', None)

Here is the caller graph for this function:

Definition at line 344 of file CachingPolicyManager.py.

00344 
00345     def getVary( self ):
00346         """
00347         """
00348         return getattr(self, '_vary', '')

Here is the caller graph for this function:

Does this request match our predicate?

Definition at line 379 of file CachingPolicyManager.py.

00379 
00380     def testPredicate(self, expr_context):
00381         """ Does this request match our predicate?"""
00382         return self._predicate(expr_context)

Here is the caller graph for this function:


Member Data Documentation

Definition at line 279 of file CachingPolicyManager.py.

Definition at line 278 of file CachingPolicyManager.py.

Definition at line 280 of file CachingPolicyManager.py.

Definition at line 268 of file CachingPolicyManager.py.

Definition at line 267 of file CachingPolicyManager.py.

Definition at line 272 of file CachingPolicyManager.py.

Definition at line 270 of file CachingPolicyManager.py.

Definition at line 271 of file CachingPolicyManager.py.

Definition at line 276 of file CachingPolicyManager.py.

Definition at line 265 of file CachingPolicyManager.py.

Definition at line 282 of file CachingPolicyManager.py.

Definition at line 281 of file CachingPolicyManager.py.

Definition at line 266 of file CachingPolicyManager.py.

Definition at line 275 of file CachingPolicyManager.py.

Definition at line 273 of file CachingPolicyManager.py.

Definition at line 274 of file CachingPolicyManager.py.

Definition at line 269 of file CachingPolicyManager.py.

Definition at line 277 of file CachingPolicyManager.py.


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