It loads bunch of DataObject
instances into Session
cache. Consequently all these objects become available without database roundtrip.
For example you have an array of Key
s and you are going to iterate this array and to process some way corresponding DataObject
instances. In this case Preload
can help you to proceed this operation faster. It would look like the following:
// Large array of keys
Key[] allKeys = callContext.GetAllKeys();
int processedCount = 0;
int totalCount = allKeys.Length;
// Lets process all keys part by part
while (processedCount < totalCount) {
int remainder = totalCount - processedCount;
Key[] keys = new Key[remainder > maxPreloadCount ? maxPreloadCount : remainder];
Array.Copy(allKeys, processedCount, keys, 0, keys.Length);
processedCount += keys.Length;
StrongReferenceHolder srHolder = session.Preload(keys); // Keep reference to srHolder to prevent garbage collection!!!
// Now all objects from keys array are loaded into Session cache
for (int index = 0, count = keys.Length; index < count; index++) {
Key key = keys[index];
NET.DataObject dObj = session[key]; // Will work without database roundtrip
// All manipulations with dObj here
}
// Release preloaded instances references (Could be omited)
srHolder.Clear();
}
(Example has taken from ObjectSetRequestProcessor
the service which prepares offline instances to be sent to a client ObjectSet
)
answered
Nov 25 '10 at 13:22
Alex Ustinov
248●4