\r\n

51Degrees API Documentation  4.2Newer Version 4.4

Lazy Loading

Introduction

Lazy loading is a concept whereby an object is not loaded until it is actually needed. This can mean that it does not start loading until it is required, or it is loaded in the background so that there is no delay in the execution of other logic. The latter is usually preferable, as loading in the background often results in no waiting at all (i.e. by the time the object is needed, it has already been loaded).

In the context of a Pipeline, lazy loading refers to the way values are populated in an aspect data. Usually the default is to not lazily load them, so an aspect engine's processing does not finish until all values have been populated. When lazy loading is configured in an aspect engine, values begin to load in another thread, and other processing can continue.

Caveats

Getting an aspect property's value from an aspect data which has been lazily loaded has the added complexity of the value not yet being known. Consequently, an exception that would otherwise have occurred during the Pipeline's processing stage has now been deferred until the point at which a value is fetched. When lazy loading is enabled, this extra possibility of an error should be taken into consideration.

Configuration

Lazy loading has two main configuration options.

Property Timeout

As it is not known at the point of fetching an aspect property's value whether or not it has been populated, a timeout option is available. This is the time to wait for the value before throwing an exception.

Cancellation

In languages where it is possible, a 'cancellation token' can be provided. This is a means of canceling all processing which is still being carried out internally to the aspect data.

Implementation

Select a tab to view language specific implementation details.