more defensive get_cached_payload function

@czue 
This should be wrapped in a `try`/`finally` so the original value gets reset even if this throws an exception.