Fix threading issues in refresh_dev_names in MEDIA_DEV_MODE

In development mode mediagenerator clears/modifies global mutable state in-place, which causes problems when running a threaded version of dev_appserver. This patch (1) makes the existing caching methods threadsafe and (2) adds a lock to `refresh_dev_names` where global state needs to be changed atomically.