This is not thread safe. There are ways to cache things in a thread-safe manner, see https://twiki.cern.ch/twiki/bin/view/CMSPublic/FWMultithreadedThreadSafeDataStructures