Re-generate autoloader cache when cached file does not exists (closes #2508)

Also:
- Atomically write the `.autoloader.cache` file.
- Re-generation is locked in order to prevent multiple processes from
  re-indexing the files.