Understanding Result Caching
When you submit a request to MarkLogic Server, the results are returned to your application in a ResultSequence
. By default, the XdmItem
objects in the sequence are cached. That is, all the result items are read and buffered in memory. Cached results do not tie up any connection resources and are usually preferred.
A non-cached, or streaming, ResultSequence
may only be accessed sequentially and hold the connection to MarkLogic Server open. Individual results may only be read once and on demand, so the result set consumes less memory, at the cost of less efficient access.
If you are retrieving large results, such as a large binary document, you may disable result caching to conserve memory. You may disable result caching per request by creating a RequestOption
object with the setting disabled, and associating it with a request, either directly with Request.setOptions
or passing it as a parameter to a Request creation method such as Session.newAdhocQuery
. You may disable result caching per session by setting the default request options for the session using Session.setDefaultRequestOptions
.
For details, see the ResultSequence
XCC javadoc.