To be able to speed up processing times of XML views that make heavy use of the preprocessor feature, you can use the view cache to store its processed XML source. Then according network requests for the source and all preprocessor runs that modify the XML source are skipped and the source is taken from the cache.
To make sure that the cache always contains the latest view data, the cache has to be invalidated whenever the data changes that is needed for preprocessing. When the cache is invalidated, all resources are processed again and the cache gets filled with new data.
Parts of this feature are currently still experimental. For more information, see the API Reference for sap.ui.xmlview in the Demo Kit.
SAPUI5 version changes
Descriptor file (manifest.json)
Locale (for each locale one cached resource is being created)
For each additional component that may have an influence on the preprocessing results of the view source, like OData metadata, you have to implement the invalidation by adding additional keys to the cache configuration.
Google Chrome as of version 49 for desktop
Internet Explorer as of version 11 for desktop
The XML view has to be loaded asynchronously.
var sCalculatedCacheKey = oKeyProvider.getCacheKey(); sap.ui.xmlview({ async: true, id: "cacheableView", viewName: "my.cacheableView", cache: { // one key is mandatory keys:[sCalculatedCacheKey] } });
var pCalculatedCacheKey = oKeyProvider1.getCacheKeyPromise(); var sAnotherKey = oKeyProvider2.getCacheKey(); sap.ui.xmlview({ async: true, id: "cacheableView", viewName: "my.cacheableView", cache: { keys: [ // several key providers, at least one pCalculatedCacheKeyPromise, sAnotherKey ] } });
If you want to implement a preprocessor that has influence on the creation of views, for example, by changing the XML code, you can use function getCacheKey. With this function, the view can find out whether the preprocessor triggers changes that invalidate the cache. The function returns a cache key or a promise that resolves a cache key. For more information, see the API Reference for sap.ui.core.mvc.View.Preprocessor in the Demo Kit.
// Example preprocessor implementation sap.ui.define(['jquery.sap.global', 'sap/ui/base/Object'], function(jQuery, BaseObject) { 'use strict'; var TestPreprocessor = BaseObject.extend("smy.TestPreprocessor", {}); TestPreprocessor.process = function(vSource, sCaller, mSettings) { return doSomething(vSource)); }; TestPreprocessor.getCacheKey = function(oViewInfo) { return sCacheKey; }; return TestPreprocessor; }, /* bExport= */ true);