I wondered if it was possible to tell BaseX (or to have it understand by itself) that it can cache and reuse the results of
/tei:TEI/tei:text/tei:body//tei:ELEM
and only apply PREDICATE on the saved set of results.
Is something like this available in BaseX?
No, I'm afraid (and I'm not sure how to easily realize this for arbitrary requests). If performance is critical, and if you believe nothing more can be done, you could still think about creating additional index structures for your data and access these instead (just as Fabrice motivated in his reply).
Unfortunately all I got back was a "Unknown option 'CACHEQUERY'" error (with BaseX 8.2.1). Any idea why?
I now know why: Because it has recently been removed. All it did was to cache results before returning them to the client instead of streaming them. This option was only used for our GUI, but another solution has now been found there.
I have updated our documentation. Thanks for the hint, Christian