I have a dict that I need to be persistent. It's not tied to content per se nor is it even specific to one Plone site. There is some functionality associated with it so I was originally going to just write a global utility. But it does need to actually save some data, and thus be persistent. I could make the utility a subclass of Products.CMFCore.utils.UniqueObject but that seems like overkill here. I don't need it to be accessible in the ZMI or traversable, I just want a dict stored in a db.
What I tried to do was something like this
_history = schema.Dict(
self._history = OOBTree()
This is incomplete - self._history will always be reinitialized to a new OOBTree on start up. What am I missing to make this something actually persistent, or is this just a completely wrongheaded approach?
Zope utilities live in two worlds: global utilities, maintained in the so called GlobalComponentRegistry and managed via ZCML, and so called local (persistent) utilities, maintained in a local component registry and managed via the registry's API.
You can find examples how to register a local (persistent) utility in Products.CMFCore (and dm.zope.saml2.authority.move_handler).
In an annotation you store a BTree object, so I think conflict might happen. Let's say you have an OOBTree in an annotation and then one thread assigns a key value in there, while another thread does the same just before the change done by the first is stored. In such case I would expect a conflict.
Take it with a grain of salt, maybe I am missing something.