5.3.1 Enumeration Behavior
Active Directory providers can follow one of three models for caching collections during enumeration. The caching model affects the behavior of Active Directory when an object in a collection is deleted from the underlying namespace "outside" of Active Directory.
1. Collections are cached in advance. The collection of object instances is retrieved from the underlying namespace in its entirety when _NewEnum is called to create a new enumerator object. If the source object for an Active Directory object instance in the retrieved collection is deleted from the underlying namespace the client does not become aware of the deletion until a GetInfo or SetInfo attempts to access the source instance.
2. Collections are incrementally cached. The collection is retrieved from the underlying namespace one object at a time when IEnumVARIANT::Next is called. ::Reset will return to the beginning of the collection in the cache and ::Next will return cached objects until the end of the cache is reached, at which point new objects will be added from the underlying store. Once an Active Directory object instance is in the cache the client will not become aware of its deletion from the underlying namespace until a GetInfo or SetInfo attempts to access the source instance.
3. Collections are not cached. The collection is retrieved from the underlying namespace one object at a time when IEnumVARIANT::Next is called. ::Reset will return to the beginning of the collection in the underlying store. ::Next and ::Reset operations cannot retrieve deleted objects, since the objects are fetched on demand from the underlying namespace. Only the "current" object is cached; if the current object is deleted, the client will not become aware of its deletion from the underlying namespace until a GetInfo or SetInfo attempts to access the source instance.
Regardless of the caching model implemented by a given provider, it is important to note that Active Directory enumeration returns Active Directory interfaces to the caller. Active Directory applications should cache the returned interface pointers for any object(s) they intend to manipulate, to avoid the overhead of obtaining a new interface pointer. For example, a Visual Basic program that enumerates a container and populates a listbox with names can cache the interface pointers associated with the names for later use. This approach will provide greater performance than populating the listbox during enumeration and obtaining a new interface pointer when the user makes a selection.