I'm seeking for feedback, advice, ideas about the following scenario.
I have a site with a mega menu in the top and a site map in the bottom. This means I have to construct a site map, i.e HTML code containing a tree of
<li> elements containing links for all the content in the site, down to a certain depth, let's say, 3 levels.
It happens that this is slow on Plone. Here is my code: https://gist.github.com/rafaelbco/4bfc512c6b81884298d997236617b7cf The bulk of the work is done by the function
plone.app.layout.navigation.navtree.buildFolderTree. I'm on Plone 4.x with Dexterity-only content types.
Besides being slow, it fills up the DB cache with a lot of objects. I don't know what kind of objects end up in the cache, but I can see the number of objects in ZMI / Control Panel. My code avoids all calls to
getObject. Only catalog brains are used. Any ideas?
So I resort to caching the generated HTML. I encountered the following issues, regardless the specifics of the caching approach:
I have to cache one sitemap per user.
Reality is a bit better than that: I could cache one version per set of groups, because the way role assignments are handled the site. But still ...
I have to invalidate the entire cache every time something changes in the site.
Every change is a potential change in the sitemap. I thought about using event handlers to figure out if the cache must be invalidated or not, or to invalidate just a portion of the site map, but it seems a lot of work and somewhat fragile.
Regarding the caching storage, I could still not decide what is better, considering a multiple Zope instances deploy:
Cache in memory.
Each instance has it's own cache.
Cache on ZODB, using an
OOBTreeannotated in the Portal root.
All instances share the cache, which is a good thing. However it polutes the Undo history and can be slow if the cache is invalidated a lot.
Cache in something external and shared by all instances, like memcached.
I have not tried it yet. The main drawback I can see is it's one more service to configure/deploy/monitor/etc.
Any feedback is appreciated. Throw your crazy ideas. Ask questions. Ask for money. I need help! _ _