__before_publishing_traverse__ and caching
Hi, I have a Python product which features a __before_publishing_traverse__ method, setting some REQUEST variables and in turn deleting the optional "([language],[template])" path element. Now I'd like to get the Cache Manager to cache these http://the.domain/path/to/site/(en,default)/home etc. pages (and, of course, appropriate versions of http://the.domain/path/to/site/(en,default)/site.css etc as well). However, when I create a RAM Cache Manager in the site object, this won't use these virtual paths (with "(en,default)" just behind the site object) but the physical ones. Is it possible to tell the Cache Manager to cache just every request to a page object, preserving the given path? tia, Tobias
Tobias Herp wrote at 2003-10-22 15:43 +0200:
I have a Python product which features a __before_publishing_traverse__ method, setting some REQUEST variables and in turn deleting the optional "([language],[template])" path element. Now I'd like to get the Cache Manager to cache these http://the.domain/path/to/site/(en,default)/home etc. pages (and, of course, appropriate versions of http://the.domain/path/to/site/(en,default)/site.css etc as well).
However, when I create a RAM Cache Manager in the site object, this won't use these virtual paths (with "(en,default)" just behind the site object) but the physical ones. Is it possible to tell the Cache Manager to cache just every request to a page object, preserving the given path?
The objects are themselve responsible for caching. Thus, your objects should be able to override the "ZCachable" methods to do what you want. Dieter
Dieter Maurer wrote:
Tobias Herp wrote at 2003-10-22 15:43 +0200:
I have a Python product which features a __before_publishing_traverse__ method, setting some REQUEST variables and in turn deleting the optional "([language],[template])" path element. Now I'd like to get the Cache Manager to cache these http://the.domain/path/to/site/(en,default)/home etc. pages (and, of course, appropriate versions of http://the.domain/path/to/site/(en,default)/site.css etc as well).
However, when I create a RAM Cache Manager in the site object, this won't use these virtual paths (with "(en,default)" just behind the site object) but the physical ones. Is it possible to tell the Cache Manager to cache just every request to a page object, preserving the given path?
The objects are themselve responsible for caching. Thus, your objects should be able to override the "ZCachable" methods to do what you want.
My objects inherit Cacheable, and when I go to the 'Associate' tab of the RAM Cache Manager and 'Locate' 'all' objects of my page type, they are listed. I can even associate them. But even when I do a full reload of a associated page, it isn't added to the cache. Isn't it sufficient to inherit Cacheable, and the result of the index_html method will be cached? What more is needed? Furthermore, for each of my pages there is possibly more than one version: when my site supported english and german contents, and provided the page templates 'default' and 'mozilla', their URLs would optionally contain '(en,default)', '(de,default)', '(en,mozilla)' or '(de,mozilla)' as the first path segment behind the site. These URLs won't ever be listed in the association tab, right? So how can I get them cached? Can't my objects be recognised as cacheable just by their type, and automatically added when first accessed? Thanks, Tobias
Tobias Herp wrote:
Isn't it sufficient to inherit Cacheable, and the result of the index_html method will be cached? What more is needed?
No its not sufficient, you have to actually use the ZCacheable API if you want to benefit from a cache manager. Read the source for another product like PythonScripts or PageTemplates to see examples of how to do it, but more importantly read OFS/Cache.py to see how it actually works.
These URLs won't ever be listed in the association tab, right? So how can I get them cached? Can't my objects be recognised as cacheable just by their type, and automatically added when first accessed?
Well the associations tab lists objects, not URLs, so presumebly you're correct. If your objects return different values depending on the context they are called from (which IIUC, is the case) then you should make sure the context is included in the keywords data presented to ZCacheable_set(). -- Jamie Heilman http://audible.transient.net/~jamie/ "Most people wouldn't know music if it came up and bit them on the ass." -Frank Zappa
Jamie Heilman wrote:
Tobias Herp wrote:
Isn't it sufficient to inherit Cacheable, and the result of the index_html method will be cached? What more is needed?
No its not sufficient, you have to actually use the ZCacheable API if you want to benefit from a cache manager. Read the source for another product like PythonScripts or PageTemplates to see examples of how to do it, but more importantly read OFS/Cache.py to see how it actually works.
Ok, after some reading in ZopePageTemplate.py my understanding is as follows: - when my object changes, ZCacheable_invalidate must be called - in my index_html, try to get a cached value via ZCacheable_get - if there is no cacheable value yet, store it via ZCacheable_set - the keyset to use is a dictionary containing the request variables which are the keys, e.g. { 'language': REQUEST.get('language'), 'template': REQUEST.get('template'), } Correct? Still missing something? Thanks, Tobias
Tobias Herp wrote:
Correct? Still missing something?
sounds right to me, try it -- Jamie Heilman http://audible.transient.net/~jamie/ "I was in love once -- a Sinclair ZX-81. People said, "No, Holly, she's not for you." She was cheap, she was stupid and she wouldn't load -- well, not for me, anyway." -Holly
Tobias Herp wrote:
Jamie Heilman wrote:
Tobias Herp wrote:
No its not sufficient, you have to actually use the ZCacheable API if you want to benefit from a cache manager. Read the source for another product like PythonScripts or PageTemplates to see examples of how to do it, but more importantly read OFS/Cache.py to see how it actually works.
Ok, after some reading in ZopePageTemplate.py my understanding is as follows:
- when my object changes, ZCacheable_invalidate must be called
- in my index_html, try to get a cached value via ZCacheable_get
- if there is no cacheable value yet, store it via ZCacheable_set
- the keyset to use is a dictionary containing the request variables which are the keys, e.g. { 'language': REQUEST.get('language'), 'template': REQUEST.get('template'), }
Correct? Still missing something?
Just for the records: This works so far :-) Thanks, Tobias
participants (4)
-
Dieter Maurer -
Jamie Heilman -
Tobias Herp -
Tobias Herp