Knowledgebase:
Keeping XML structures memory resident and accessible to XQuery endpoints.
19 March 2015 06:28 PM

Introduction

MarkLogic Server provides a couple of useful techniques for keeping values in memory or resolving values without having to scan for documents on-disk.

Options

There are a few options available:

1. cts:element-values performs a lexicon lookup so it's directly getting those values from the range indexes; you can add an options node and use the "map" parameter to get the call to return a map directly as per the documentation, which may give you what you need without having to do any further work.

See: http://docs.marklogic.com/cts:element-values

2. Storing a map as a server field is a popular approach and is widely used for storing data that needs to be accessed routinely by queries.

Bear in mind that there is a catch to this approach as the map is not available to all nodes in a cluster - it is only available to the node responsible for evaluating the original request, so if you're using this technique in a clustered environment, the results may not be what is expected.

Also note that if you're planning on storing a large number of maps in server fields on nodes on the cluster, it's important to make sure the hosts are provisioned with enough memory to accommodate these maps on top of group level caches and memory for query allocation, stands, range indexes document retrieval and the like.

See: http://docs.marklogic.com/map:map

And: http://docs.marklogic.com/xdmp:set-server-field

3. xdmp:set only allows you to set a value for the life of a single query but this technique can be useful in some circumstances - especially in situations where you're interested in keeping track of certain values throughout the processing of a module or a function within a module.

See: http://docs.marklogic.com/xdmp:set

4. If you have a situation where you have a large number of complex queries - particularly ones where lexicon lookups or calls to range indexes won't resolve the data you need and where lots of documents will need to be retrieved from disk, you should consider using registered queries.

See: http://docs.marklogic.com/cts:registered-query

Note that registered queries utilise the List Cache so, if you plan to adopt this method, we recommend careful testing to ensure your caches are sized sufficiently to suit the needs of your application.

(1 vote(s))
Helpful
Not helpful

Comments (0)