Re: [Plone-developers] CacheFu overhaul
xiru <[email protected]>
| Newsgroups | gmane.comp.web.zope.plone.archetypes.devel,gmane.comp.web.zope.plone.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi Geoff, I just remembered that I have a monkey patch here at the parliament cluster (a nice one) that solved that Issue with content types that does not invoke caching policy manager. I hope you like It, review my code and integrate it to CacheFu. Best Regards Fabiano Weimar On 2/7/06, Geoff Davis <geoff-wGuDV/[email protected]> wrote: > > Hi all-- > > I am doing an overhaul of CacheFu. I have fixed (I think) all the > outstanding bugs, and I have completely revamped the way that CacheFu is > configured. Once you get your squid.conf and httpd.conf files right, > setup should much easier: pretty much all cache settings are now > controlled from portal_cache_settings (navigate to it in the ZMI, then use > the View tab to actually do something useful). No more script > customizations should be required. > > The new code is in svn in the geoffd-cachefuageddon branch. > > I've added lots of unit tests, and they all pass, but I still haven't done > much testing with an actual squid instance. > > NOTE: if you have an existing cachefu setup with squid behind apache, you > will need to modify your httpd.conf file and squid.conf files slightly. > > A few things: several content types do not invoke caching policy manager > to set their headings. I believe this includes Files, FSFiles, Images, > FSImages, and possibly ATFiles and ATImages (at least for the downloads). > I don't really care for my use case, but it would be nice to have these > controlled by a sane caching policy. Patches gratefully accepted. > > I think content gzipping will now work, but I haven't tested it at all. > Assuming it works, your content will be stored pre-gzipped in the cache. > > Geoff > > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. Do you grep through log > files > for problems? Stop! Download the new AJAX search engine that makes > searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642 > _______________________________________________ > Plone-developers mailing list > Plone-developers-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org > https://lists.sourceforge.net/lists/listinfo/plone-developers > -- Fabiano Weimar dos Santos Plone Developer and Consultant
patch.py
(text/x-python, 3.4 KB)
from OFS.DTMLMethod import DTMLMethod
from OFS.Image import Image, File
from Acquisition import aq_base
from DateTime import DateTime
from Products.CMFCore.FSImage import FSImage
from Products.CMFCore.FSFile import FSFile
from Products.CMFCore.FSDTMLMethod import FSDTMLMethod
from Products.CMFCore.utils import _ViewEmulator, _setCacheHeaders
from Products.StandardCacheManagers.AcceleratedHTTPCacheManager import AcceleratedHTTPCache
from zLOG import LOG, INFO
def log(msg):
LOG('CacheFu', INFO, msg)
log('Applying high performance cache patch...')
PATTERN = '__CacheFu_%s__'
def call(self, __name__, *args, **kw):
return getattr(self, PATTERN % __name__)(*args, **kw)
WRAPPER = '__CacheFu_is_wrapper_method__'
ORIG_NAME = '__CacheFu_original_method_name__'
def isWrapperMethod(meth):
return getattr(meth, WRAPPER, False)
def wrap_method(klass, name, method, pattern=PATTERN):
old_method = getattr(klass, name)
if isWrapperMethod(old_method):
log('Re-wrapping %s.%s.' %
(klass.__name__, name))
else:
log('Wrapping %s.%s.' %
(klass.__name__, name))
new_name = pattern % name
setattr(klass, new_name, old_method)
setattr(method, ORIG_NAME, new_name)
setattr(method, WRAPPER, True)
setattr(klass, name, method)
def unwrap_method(klass, name):
old_method = getattr(klass, name)
if not isWrapperMethod(old_method):
raise ValueError, ('Trying to unwrap non-wrapped '
'method %s.%s.' % (klass.__name__, name))
orig_name = getattr(old_method, ORIG_NAME)
new_method = getattr(klass, orig_name)
delattr(klass, orig_name)
setattr(klass, name, new_method)
def patch_ofs():
# Set default cache manager to 'CacheSquid' for most objects.
log('Associating object with HTTP Cache Manager...')
for klass in (Image, File, FSImage, FSFile):
log('Associating %s.' % klass.__name__)
setattr(klass, '_Cacheable__manager_id', 'HTTPCache')
def ZCache_set(self, ob, data, view_name, keywords, mtime_func):
# Hook AcceleratedHTTPCache to use CMF's caching policy manager.
res = call(self, 'ZCache_set', ob, data,
view_name, keywords, mtime_func)
_setCacheHeaders(_ViewEmulator().__of__(ob), extra_context=keywords)
return res
def patch_http_cache():
wrap_method(AcceleratedHTTPCache, 'ZCache_set', ZCache_set)
def fs_modified(self):
"""What's the last modification time for this file?
"""
self._updateFromFS()
return DateTime(self._file_mod_time)
def ofs_modified(self):
"""What's the last modification time for this object?
"""
if hasattr(aq_base(self), 'bobobase_modification_time'):
return self.bobobase_modification_time()
if hasattr(aq_base(self), '_p_mtime'):
return DateTime(self._p_mtime)
return DateTime()
def patch_ofs_modified():
# Add 'modified' method to File/Image/DTMLMethod.
for klass in (Image, File, DTMLMethod):
if hasattr(klass, 'modified'):
continue
log('Adding "modified" method to %s.' % klass.__name__)
setattr(klass, 'modified', ofs_modified)
def patch_fs_modified():
# Add 'modified' method to File/Image/DTMLMethod.
for klass in (FSImage, FSFile, FSDTMLMethod):
if hasattr(klass, 'modified'):
continue
log('Adding "modified" method to %s.' % klass.__name__)
setattr(klass, 'modified', fs_modified)
patch_ofs_modified()
patch_fs_modified()
patch_ofs()
patch_http_cache()