Add lock for the closeCacheFile at runtime.

We move the local mutex of the addToEntryCache() function to the member
of the EntryCache class. Everytime we would like to modify the entry
cache, we should lock this mutex first, including addToEntryCache and
closeCacheFile. This should be followed when we add more functions to
EntryCache class in the future.
Refine the coding style of the runtime

Reorder the function definition and add some comments.