Make access to the dependency cache threadsafe.

This wraps all accesses to the dependency cache in a mutex so that the global thread-unsafe hash object won't trigger hangs in JRuby.