Fixes #1186
Port fixes to Tomcat as well
Fix logic when the cache is changed after startup