Hi John, I'm cc'ing this back to the list...
Hi, I have been using the thumbnail hotfix and am having trouble getting the functions to use cacheable thumbnails.
I put what I *think* is the right stuff to let the thumbs be cacheable by a RAMcache, but so far my cries for help on the subject, and documentation for how to take advantage of RAMcache, have been unanswered, so I don't know if that works. But the http tags for letting the client browser cache the images are working.
I have been reading __init__.py to get some understanding of how to use this code. Currently, I have a simple DTML script to iterate over a Folder and make thumbnails of each image in the folder with links to the original.
I'll paste the relevant code from my CMFPhotoAlbum product, which I know works: <dtml-in "objectItems(['Image','Portal Image'])" sort=id size=qsize start=qstart> <dtml-if "(_['sequence-index']%5)==0"> </tr> <tr> </dtml-if> <td valign=bottom align=center> <a href="<dtml-var "_['sequence-key']+'/viewimg?img='+_['sequence-key']">"> <dtml-var "title_or_id()"><br> <dtml-with stylesheet_properties> <dtml-var "tag(width=80, height='',border=2, style='border-color:' + base_font_color + ';background-color:' + base_font_color)"> </dtml-with> </a> </td> </dtml-in>
If I read this correctly, this is *not* using the function 'thumb' that is defined in __init__.py, but is using the browser to resize the images. The problem with this, of course, is that if you have a lot of images and want to frequently reload the page, it can be slow.
...exactly why I made this product!
I that source code for 'tag' used the logic 'if height and width are integers call thumb, e
that's correct.
lse use the height and width attributes of html'. The function 'thumb' calls:
thumbnail_file = self.ZCacheable_get(view_name='thumb', keywords=keys)
so it appears to me that this is thumbnail cacheing, which is the behavior I want.
this is the stuff to use an external RAMcache. The idea is that you would have one RAMcache on your site to cache your calculated thumbnails. Architecturally, that's usually what you'd want. The part I dont' know is, how could you get any newly created image to connect to this RAMCache automatically? Right now, it seems to work if you create the image and the RAMcache and associate it manually via the ZMI, but what a pain! I wish I knew how to do this within the product - e.g. associate the 'class' with the RAMcache....
My question is: how should I code the DTML so I can get the thumbnail cacheing? I tried manually setting height and width to integer values but this did not help:
<dtml-var "this().tag(40,60)"></a>
Is this because '40' and '60' here are not really integers but strings by the time they get passed to 'tag'?
Ideally, I would like to generated scaled, cached thumbnails.
one thing you can try is naming the attributes? tag(height=60,width=40), something like that.... You can see in the source that index_html generates the cacheable http headers, which will activate downstream caches.... it might even help a downstream Squid -- if anyone knows for sure, or has suggestions in that area, let me know! Marc
On Saturday 20 October 2001 05:20, marc lindahl wrote:
... this is the stuff to use an external RAMcache. The idea is that you would have one RAMcache on your site to cache your calculated thumbnails. Architecturally, that's usually what you'd want. The part I dont' know is, how could you get any newly created image to connect to this RAMCache automatically? Right now, it seems to work if you create the image and the RAMcache and associate it manually via the ZMI, but what a pain! I wish I knew how to do this within the product - e.g. associate the 'class' with the RAMcache....
Without knowing the answer in detail... _Everything_ you can do with the ZMI you can do in DTML (because that's what it is). Just go to the ZMI page that does what you want, and look what function is being called. Somewhere in your Zope installation you will find the corresponding DTML _file_ (this time it's lib/python/OFS/dtml/cmassoc.dtml), and see what's happening there. I was able to do lots of things by simply copying the function calls from ZMI pages... I don't know exactly what you want you want to do in detail, but this file should bring lots of enlightnment... I never looked into CacheManagers in detail, but it looks as if a call to ZCacheManager_locate finds associated objects, and a call to ZCacheManager_setAssociations actually establishes the associations. (that's the methods being called from the form) Searching for these function names brought me to lib/python/OFS/Cache.py: def ZCacheManager_setAssociations(self, props=None, REQUEST=None): '''Associates and un-associates cacheable objects with this cache manager. ''' These two files should actually be all you need to mimick the ZMI's behavior. The right call to myRAMCache.ZCacheManager_setAssociations is probably what does the trick (doing that whenever you create an image object, maybe some ZClass derived from ZImage that has this call in its constructor ("add" method)). What you would need to gather up is what sort of information ZCacheManager_setAssociations expects in "props" and "REQUEST", which in your case will probably be a very small subset of what you find in the ZMI's dtml file. hth, and sorry for not providing a copy&paste answer, I just don't know enough about ZCacheManagers, Danny
Thanks for the answer... The two problems with associating at creation time: 1. The RAMCache name (and possibly location in the heirarchy) has to be preset somehow... though I guess it could be via a property. But that's another question - how to have a property page in a Python product like you can do in a ZClass based product.... 2. If you want to change anything later it's a pain (like the location of the cache, and of course, there's a question of what happens if you cut/copy/paste e.g. the image itself). But besides that it's the only way to do it... Also, I still can't find good doc on how the RAMCache should be set up, etc. for something like this...
From: Danny William Adair <danny@adair.net>
These two files should actually be all you need to mimick the ZMI's behavior. The right call to myRAMCache.ZCacheManager_setAssociations is probably what does the trick (doing that whenever you create an image object, maybe some ZClass derived from ZImage that has this call in its constructor ("add" method)). What you would need to gather up is what sort of information ZCacheManager_setAssociations expects in "props" and "REQUEST", which in your case will probably be a very small subset of what you find in the ZMI's dtml file.
hth, and sorry for not providing a copy&paste answer, I just don't know enough about ZCacheManagers,
Danny
participants (2)
-
Danny William Adair -
marc lindahl