Log in |
Implementation NotesThis article describes the implementation of the new Pickle Cache. You probably want to read this documentation about why a change was needed and the FAQ before continuing. See also these release notes, and API changes. The pickle cache stores persistent objects in a dictionary. Objects are stored under three different regimes: Regime 1: Persistent ClassesPersistent Classes are part of ZClasses. I believe the implementation of
Persistent Classes is unchanged from the original implementation: They are
stored in the Note: I added a Regime 2: Ghost ObjectsGhost objects are necessary to support references to persistent objects whose state is not yet in memory. There is no benefit to keeping a ghost object which has no external references, therefore a weak reference scheme is used to ensure that ghost objects are removed from memory as soon as possible, when the last external reference is lost. Ghost objects are stored in the This weak reference scheme leaves a dangling reference, in the dictionary,
when the last external reference is lost. To clean up this dangling reference
the persistent object dealloc function calls
Note: persistent objects now have a reference to their cache, which is set up by the cache during its setitem. Since ghost objects are stored under a different regime
to non-ghost objects, an extra Regime 3: Non-Ghost ObjectsNon-ghost objects are stored in two data structures. Firstly, in the dictionary along with everything else, with a strong reference. Secondly, they are stored in a new doubly-linked-list which encodes the order in which these objects have been most recently used. The doubly-link-list nodes, colored red in figure.4 below, contain next and previous pointers linking together the cache and all non-ghost persistent objects. The node embedded in the cache is the home position. On every attribute access a non-ghost object will relink itself just behind the home position in the ring. Objects accessed least recently will eventually find themselves positioned after the home position. Occasionally other nodes are temporarily inserted in the
ring as position markers.
The cache contains a The number of non-ghost objects is counted in
Note that objects in the sticky or changed states are still kept in the ring, however they can not be deactivated. The garbage collection process must skip such objects, rather than deactivating them. A new method |