Creates a mutex using Rails.cache in order to prevent duplicate entries from being made.
Added test for thread safety.