Memoization fixes

This PR should fix https://trac.openmicroscopy.org.uk/ome/ticket/11971 and https://trac.openmicroscopy.org.uk/ome/ticket/12019.

/cc @jianguo11