Extract common event cache and return code to a function.