Class: ICache | ./src/peak/persistence/interfaces.py | |||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
In-memory object cacheThe cache serves two purposes. It peforms pointer swizzling, and it keeps a bounded set of recently used but otherwise unreferenced in objects to avoid the cost of re-loading them. Pointer swizzling is the process of converting between persistent object ids and Python object ids. When a persistent object is serialized, its references to other persistent objects are represented as persitent object ids (oids). When the object is unserialized, the oids are converted into references to Python objects. If several different serialized objects refer to the same object, they must all refer to the same object when they are unserialized. A cache stores persistent objects, but it treats ghost objects and non-ghost or active objects differently. It has weak references to ghost objects, because ghost objects are only stored in the cache to satisfy the pointer swizzling requirement. It has strong references to active objects, because it caches some number of them even if they are unreferenced. The cache keeps some number of recently used but otherwise unreferenced objects in memory. We assume that there is a good chance the object will be used again soon, so keeping it memory avoids the cost of recreating the object. An ICache implementation is intended for use by an IPersistentDataManager.
|