Changes

Jump to navigation Jump to search
433 bytes added ,  16:20, 27 February 2020
no edit summary
The XQuery expression below serves as an example on how large files can be downloaded and written to a file with constant memory consumption:
<pre classsyntaxhighlight lang="brush:xquery">
file:write-binary('output.data', fetch:binary('http://files.basex.org/xml/xmark111mb.zip'))
</presyntaxhighlight>
If lazy items are serialized, they will be streamed as well.
|-
| width='120' | '''Signatures'''
|{{Func|lazy:cache|$items as item()*|item ()*}}<br/>{{Func|lazy:cache|$items as item()*, $lazy as xs:boolean|item()*}}
|-
| '''Summary'''
|Caches the contents data of a lazy {{Code|$itemitems}}in a sequence:<br />* contents data of lazy items will be retrieved and cached in inside the item.* non-lazy items , or lazy items with cached contents data, will simply be passed through.* 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 of a lazy items is advisable if an item will be processed more than once, or if the the targeted contents will data may not be available anymore at a later stage.
|-
| '''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:
<pre classsyntaxhighlight lang="brush:xquery">
let $file := 'data.txt'
let $text := lazy:cache(file:read-text($file))
return (file:delete($file), $text)
</presyntaxhighlight>
|}
=Changelog=
 
;Version 9.1
 
* Updated: [[#lazy:cache|lazy:cache]]: {{Code|$lazy}} argument added; support for sequences.
;Version 9.0
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu