Closed lukasgraf closed 10 years ago
thx for catching this.
@memoize
should actually be on method which is returning the record from registry. then it wouldn't break on different zodb connections.
@garbas you mean something like this?
from plone.memoize import instance
@instance.memoize
def record_from_registry(self, key):
registry = getUtility(IRegistry)
record = registry.get(key, None)
return record
But wouldn't that mean that it's not possible to edit terms in the registry TTW anymore? Since memoize()
uses the method arguments as the cache key, so even if the user changes a registry record, the key stays the same, and updates to the vocabulary will only be effective upon next restart of the zope instance. This would kind of defeat the purpose of making the terms configurable through the registry, no?
Unless maybe we use registry events to implement cache invalidation.
I looked into implementing memoizing registry records and doing proper cache invalidation, but it's definitely non-trivial and would require some substantial changes.
For the moment I would prefer if we could just fix the problem at hand, and consider caching the registry records at a later point in time (they haven't been cached up until now, after all - just a reference to the utility was kept).
I would assume that fetching the actual records is much more of an expensive operation than the getUtility
call to get the utility from the component registry. So by simply not keeping a reference to the utility performance shouldn't degrade substantially, and the problem regarding ZODB connections would be fixed.
Added a proof-of-concept implementation for caching registry records and cache invalidation in #7
Changes are looking good. :+1:
I think the caching should be processed in an separate issue, therefore i will merge that one.
In the
plone_registry
property invocabulary.py:35
a reference to the persistent utility ofplone.app.registry
is being held.This causes a problem, because the vocabulary factory will be instanciated with different contexts, which have their own ZODB connections. So in certain circumstances this will lead to the vocabulary factory's context having a ZODB connection
B
, whereas the registry utility still has a different connectionB
. This then causes aConnectionStateError
when trying to access the registry (atvocabulary.py:53
for example):Proposed solution: Don't memoize the
plone.app.registry
utility, but instead query for it every time we need to access the registry.