ISPN-4144 Cleanly shutdown intermediate M/R cache

Master only. Needs rebasing and a review. Do not integrate. See https://issues.jboss.org/browse/ISPN-4144 for more details