什么时候PersistentDict,什么时候Folder? [英] When PersistentDict, when Folder?

查看:141
本文介绍了什么时候PersistentDict,什么时候Folder?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

何时应使用PersistentDict,何时应使用文件夹?在更新,内部结构,性能等方面,它们之间有什么区别?

When should I use a PersistentDict, and when should I use a Folder? What is the difference between them in terms of updates, internal structure, performance, etc?

推荐答案

PersistentMapping只是python dict类型的一种实现(通过标准库UserDict基类),已针对该类的Persistence语义进行了调整. ZODB;不必每次更改mapping时都必须在从Persistent继承的最近的类上设置_p_changed标志.

A PersistentMapping is simply a implementation of the python dict type (via the standard library UserDict base class) adjusted for the Persistence semantics of the ZODB; it saves from having to set the _p_changed flag on the nearest class that inherits from Persistent every time you alter the mapping.

A Folder是一个更丰富的类型,用于实现事件,与Zope Web界面(ZMI)集成,Web任意属性(带有类型验证的属性),Zope权限管理,子项目验证ID,导入/导出等.子项文件夹作为属性存储在对象本身上,一些元数据存储在实例的私有dict中.

A Folder is a much richer type, implementing events, integration with the Zope web interface (ZMI), through-the-web arbitrary properties (attributes with type validation), management of Zope permissions, validation of sub-item ids, import/export, etc. Sub-items folders are stored as attributes on the object itself, with some metadata stored in a private dict on the instance.

在需要任何其他服务(权限授予,ID验证等)时,请使用Folder,否则请使用PersistentMapping.从性能上看,查找或存储项目不会有太大差异;一个是下面的直线python dict,另一个是存储项目的实例__dict__.

Use a Folder when you need any of those extra services (delegation of permissions, id validation, etc), use a PersistentMapping otherwise. Performance wise looking up or storing items is not going to differ much; one is a straight python dict underneath, the other is the instance __dict__ storing the items.

如果您希望避免冲突,则应研究 BTrees OOBTree类基本上是一个持久映射,其中值存储在持久存储区中,在大多数情况下避免冲突,并为其余情况提供冲突解决方案.

If you are looking for conflict avoidance, you should look into BTrees, the OOBTree class is basically a persistent mapping where values are stored in persistent buckets, avoiding collisions in most cases, and providing conflict resolution for the rest.

如果要使用BTree存储语义的Folder语义,请查看 Products.BTreeFolder2 和实现Folder接口但将子对象存储在OOBTree中而不是直接作为实例上的属性的附件.

If you want Folder semantics with BTree storage semantics, look at Products.BTreeFolder2, and add-on that implements the Folder interfaces but stores sub-objects in a OOBTree instead of as attributes directly on the instances.

这篇关于什么时候PersistentDict,什么时候Folder?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆