backported cache_update for lua and fixed its lock handling