A PersistentDict (now called PersistentMapping ) is a class that inherits from UserDict.IterableUserDict and persistent.Persistent.
UserDict.IterableUserDict is a built-in python class that mimics an iterable dictionary and persistent.Persistent is a Zope class that allows an instance of itself to be stored in ZODB.
Thus, PersistentDict (or PersistentMapping) is basically a dictionary that can be saved as an object in ZODB.
Normal dictionaries cannot be stored as separate objects in ZODB. They must be attributes of some class that inherits from persistent.Persistent.
PersistentDict stores its keys and values ββinside the actual dictionary (data attribute).
It is not possible to add PersistentDict through ZMI, and I think it was intended mainly for a special case when you want to store the dictionary directly in zodb.
With Folder , I think you mean the folder in zope.container.folder. A folder stores its children inside an OOBTree object, which is a container that can hold a large number of objects.
If you need a container containing instances of other types of content, then you better go with a folder.
The folder has interfaces that are not supported by PersistentDict, and these interfaces may be required for certain adapters or other components to work. For example, the ContainerModified event will fire only when the folder changes, and not in PersistentDict. There can be all kinds of gotchas like these if you use PersistentDict as a general folder.
When it comes to performance, a dictionary will usually be faster until the key space becomes very large. Then the balance is tilted to OOBTree.
source share