Changes

Jump to navigation Jump to search
91 bytes added ,  18:46, 20 July 2022
no edit summary
This [[Module Library|XQuery Module]] contains functions for handling ''lazy'' items.
In contrast to standard XQuery items, a lazy item contains a reference to the actual data, and the data itself will only be retrieved if it is requestedprocessed. Hence, possible errors will be postponed, and no memory will be occupied by a lazy item as long as its content has not been requested yet.
The following BaseX functions return lazy items:
* Lazy Base64 binaries:
** {{Function|Database|db:get-binary}}
** {{Function|Fetch|fetch:binary}}
** {{Function|File|file:read-binary}}
** {{Function|Database|db:get-binary}}
* Lazy strings:
* [[Archive Module]] (most functions)
* Conversion Module: {{Function|Conversion|convert:binary-to-string}}
* File Module: {{Function|File|file:write-binary-text}}, {{Function|File|file:write-text}} (if no encoding is specified)
* Database Module: {{Function|Database|db:put-binary}}
* File Module: {{Function|File|file:write-binary-text}}, {{Function|File|file:write-text}} (if no encoding is specified)
* [[Hashing Module]] (all functions)
{| width='100%'
|-valign="top"
| width='120' | '''Signatures'''
|{{Func|lazy:cache|$items as item()*|item()*}}<br/>{{Func|lazy:cache|$items as item()*, $lazy as xs:boolean|item()*}}
|-valign="top"
| '''Summary'''
|Caches the data of lazy {{Code|$items}} in a sequence:<br />
* If {{Code|$lazy}} is set to {{Code|true()}}, caching will be deferred until the data is eventually requested. Streaming will be disabled: Data will always be cached before a stream is returned.
Caching is advisable if an item will be processed more than once, or if the data may not be available anymore at a later stage.
|-valign="top"
| '''Example'''
|In the following example, a file will be deleted before its content is returned. To avoid a “file not found” error when serializing the result, the content must be cached:
{| width='100%'
|-valign="top"
| width='120' | '''Signatures'''
|{{Func|lazy:is-lazy|$item as item()|xs:boolean}}
|-valign="top"
| '''Summary'''
|Checks whether the specified {{Code|$item}} is lazy.
{| width='100%'
|-valign="top"
| width='120' | '''Signatures'''
|{{Func|lazy:is-cached|$item as item()|xs:boolean}}
|-valign="top"
| '''Summary'''
|Checks whether the contents of the specified {{Code|$item}} are cached. The function will always return {{Code|true}} for non-lazy items.
Bureaucrats, editor, reviewer, Administrators
13,551

edits

Navigation menu