strongloop/loopback-workspace — pull request #58 by ritch (2014-06-30 16:31:50+00:00)
Title: Only clear the loader once loadFromFile is complete

/to @bajtos

This just ensures the loader is reset once loading from disk is complete.

A brief background on why we need the loader:

- if `loadFromFile` is called twice in the same tick, the resulting cache of the second load although atomic, will destroy the cache from the previous call. This sounds like it should be fine, but since `create` can call `find() (via uniqueness validation) there is a potential for the cache to be populated multiple times after `create` has already added correct data that won't exist on disk...

The loader prevents this by only allowing a single `loadFromFile()` to occur at a time... This should be fine for most practical cases. I can think of edge cases where the disk changes during the two calls, but I'm not so concerned about that. If you have any ideas for a better fix I am glad to hear them.