Load balancing definitely throws a wrinkle in using shared memory. There are ways to address the problems, but they all come with pros and cons, you basically just need to choose which pros you like and which cons you can live with.
I.E. One can use sticky sessions. Thus when a user first access your application, all future requests are sent to the same server that handled the first request. But that means that if that server goes bye bye, all users currently stuck to it are s.o.l.
I've read of others using databases for the persistant memory. But then you have the lag involved in getting data from the database every request, though it should be fast easy to execute queries to do so. On the pro side, it does not matter which server handles the request.
This would be different then just re-running the original query every time, but rather storing the results of the original query in a tempory table space so that any complexity that might exist does not need to be repeated.