Why is fixture caching keyed on connection ?

I ask because I would like to use Spring to preload my fixtures prior to forking. (It’s taking about 6 seconds to load ~300 fixture files)

However, after forking, ActiveRecord::Base returns a new connection (probably because one needs to establish a new connection after forking).
This meant that FixtureSet.cache_for_connection returned nil even though there is a class level fixture cache.

The following monkey-patch gives me the cached fixtures again.

  • ActiveRecord::FixtureSet.class_eval do

  •  # spring reconnects - this results in a new ActiveRecord::Base.connection object
    
  •  def self.cache_for_connection(connection)
    
  •    ActiveRecord::FixtureSet.class_variable_get(:@@all_cached_fixtures).values.only
    
  •  end
    
  • end

I found this commit which I could not see an answer for my question :https://github.com/rails/rails/commit/078bd0515e8342165a4bc3b8fcc4faa318ebb188

Could it be for multiple databases or something like multi-threading ?