StartPrefetch
Document management, Performance, Concurrency
Description
Queues a background job that asks a caller-supplied IPLByteRangePrefetchPlanner which byte ranges are still needed and fetches them into the stream cache
One worker thread serves the stream; it runs the queued job with the highest priority first and the oldest job first within equal priorities
Prefetched bytes go through the same chunk cache as foreground reads and remain subject to its byte budget and least-recently-used eviction
Syntax
Delphi
Function TByteRangeStream.StartPrefetch(Planner: IPLByteRangePrefetchPlanner;
DataKind, DataIndex, Priority: Integer; MaxBytes: Int64;
ReadAheadBytes: Integer; MaxPasses: Integer): Integer;Parameters
| Planner | The planner the worker calls once per pass to obtain the next ranges and the availability status |
|---|---|
| DataKind | A caller-defined tag stored with the job and reported by GetPrefetchInfo |
| DataIndex | A caller-defined index stored with the job and reported by GetPrefetchInfo |
| Priority | PLNET_PREFETCH_PRIORITY_LOW (0), PLNET_PREFETCH_PRIORITY_NORMAL (1), PLNET_PREFETCH_PRIORITY_HIGH (2) or PLNET_PREFETCH_PRIORITY_CRITICAL (3) |
| MaxBytes | The read budget of the job in bytes; zero selects 64 MiB, and an explicit value must be at least ChunkSize |
| ReadAheadBytes | Extra bytes scheduled after each planned range; must not be negative |
| MaxPasses | The maximum number of planning passes; zero selects 128 |
Return values
| >0 | The job handle, valid for the lifetime of the stream |
|---|---|
| 0 | Planner is Nil, Priority is outside 0 through 3, MaxBytes is below one chunk, ReadAheadBytes is negative or MaxPasses is negative |
Remarks
The worker thread is created by the first call; destroying the stream cancels the remaining jobs and waits for the worker to stop
A job completes when the planner reports an availability status of 1 or 2. It fails when the planner returns False or raises, reports a negative status, plans no fetchable range, or a planned read comes back short
A job ends in the limit-reached state when an uncached read would exceed MaxBytes or when MaxPasses passes did not finish it; reads of bytes that are already cached do not count against the budget
See also
StartRangeSourcePrefetch, WaitForRangeSourcePrefetch, GetRangeSourcePrefetchState, CancelRangeSourcePrefetch, TByteRangeStreamReadAt