[Zope-CMF] caching policy manager
Dieter Maurer
dieter at handshake.de
Wed Sep 13 13:32:25 EDT 2006
Jens Vagelpohl wrote at 2006-9-13 09:15 +0200:
> ...
>It is a long-standing bug that the CMFDefault File index_html (and
>download, which is obsolete in newer CMF versions) simply defers to
>index_html from OFS.File. That one doesn't know anything about Cache
>Policy Managers, it only deals with the Zope ZCacheable cache manager
>mechanism.
I have defined CMF-aware ZODB object types. The one for "File" looks
like this:
# DM 2005-11-02: added
""" CMF 'File' variant (CMF Cache Policy Manager aware)"""
from OFS.Image import File, manage_addFileForm, cookId
from utils import _setCacheHeaders, _ViewEmulator
class CMFFile(File):
'''CMF cache policy manager aware file.'''
meta_type = 'CPM aware File'
def index_html(self, REQUEST, RESPONSE):
' '
r = File.index_html(self, REQUEST, RESPONSE)
if self.ZCacheable_getManager() is None:
# not none cache manager already taken care of
_setCacheHeaders(self._getCPMCachingWrapper(), extra_context={})
return r
# DM 2006-05-17: more modular CPM caching
def _getCPMCachingWrapper(self):
return _ViewEmulator().__of__(self)
# essentially a copy of "OFS.Image.manage_addFile" -- we should probably
# use "ReuseUtils".
def manage_addFile(self,id,file='',title='',precondition='', content_type='',
REQUEST=None):
"""Add a new File object.
Creates a new File object 'id' with the contents of 'file'"""
id=str(id)
title=str(title)
content_type=str(content_type)
precondition=str(precondition)
id, title = cookId(id, title, file)
self=self.this()
# First, we create the file without data:
self._setObject(id, CMFFile(id,title,'',content_type, precondition))
# Now we "upload" the data. By doing this in two steps, we
# can use a database trick to make the upload more efficient.
if file:
self._getOb(id).manage_upload(file)
if content_type:
self._getOb(id).content_type=content_type
if REQUEST is not None:
REQUEST['RESPONSE'].redirect(self.absolute_url()+'/manage_main')
def initialize(context):
context.registerClass(
CMFFile,
permission='Add Documents, Images, and Files',
constructors=(manage_addFileForm,
manage_addFile),
)
--
Dieter
More information about the Zope-CMF
mailing list