How do you exclude a basic type property of a persistent object from being persistent?

StackOverflow https://stackoverflow.com/questions/13079904

  •  14-07-2021
  •  | 
  •  

سؤال

For example if the type is an int or a str property of an object, how would you exclude it in the object's class. Is it like you have to declare a decorator before the property, what is it then?

هل كانت مفيدة؟

المحلول

Persistent Rules:

  • Your objects, and their attributes, must be “pickleable”.
  • Your object cannot have any attributes that begin with ‘p’.
  • Attributes of your object that begin with _v_ are “volatile” and are not saved to the database (see next section).
  • You must explicitly signal any changes made to mutable attributes (such as instances, lists, and dictionaries) or use persistent versions of mutable objects, like
    ‘ZODB.PersistentMapping’

The third rule is that all object attributes that begin with _v_ are “volatile” and are not saved to the database. This means that as long as the persistent object is in Zope memory cache, volatile attributes can be used. When the object is deactivated (removed from memory) volatile attributes are thrown away.

Volatile attributes are useful for data that is good to cache for a while but can often be thrown away and easily recreated. File connections, cached calculations, rendered templates, all of these kinds of things are useful applications of volatile attributes. You must exercise care when using volatile attributes. Since you have little control over when your objects are moved in and out of memory, you never know when your volatile attributes may disappear.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top