Package Products :: Package ZenUtils :: Module AutoGCObjectReader :: Class AutoGCObjectReader |
[hide private]
[frames] | no frames]

# Class AutoGCObjectReader

source code

    ZODB.serialize.ObjectReader --+
                                  |
                                 AutoGCObjectReader

ZODB has semipeculiar behavior wherein the object cache is only garbage collected at the transaction boundaries. If, within a transaction, one wishes to read a number of objects greater than the configured object cache size, the cache, and therefore memory, will simply grow with each read object.

This makes sense, when you think about it. Removing cached objects out from under existing references could have horrible effects, so it is only safe when beginning a new transaction (or aborting an existing one). Unfortunately, we have several cases where we need to read an enormous number of objects within a transaction, but don't need to write anything.

This class replaces a ZODB.Connection.Connection's existing ObjectReader. It will garbage-collect the cache every n objects. To enforce integrity, it will also abort any open transaction after cleaning the cache. It is safe ONLY when you are certain that the open transaction has not modified any objects.

Instance Methods | [hide private]
__init__(self, orig_reader, chunk_size=1000) | source code
garbage_collect_cache(self) | source code
load_persistent(self, oid, klass) | source code
get_original(self) | source code
Inherited from `ZODB.serialize.ObjectReader`: `getClassName`, `getGhost`, `getState`, `load_multi_oid`, `load_multi_persistent`, `load_oid`, `load_persistent_weakref`, `setGhostState` Inherited from `ZODB.serialize.ObjectReader` (private): `_get_class`, `_get_unpickler`, `_persistent_load`

Class Variables | [hide private]
| _orig_reader = `None`
| _counter = `0`
| _chunk_size = `1000`
Inherited from `ZODB.serialize.ObjectReader`: `loaders`

Method Details | [hide private]

### __init__(self, orig_reader, chunk_size=1000) (Constructor) | source code
Overrides: ZODB.serialize.ObjectReader.__init__

### load_persistent(self, oid, klass) | source code
Overrides: ZODB.serialize.ObjectReader.load_persistent