Skip to content

Commit f10f89e

Browse files
committed
Don't cache classes unless the environment permits it
Fixes #264.
1 parent 9b43393 commit f10f89e

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Avoid `warning: already initialized constant APP_PATH` when running
77
rails commands that do not use spring (e.g. `bin/rails server` would
88
emit this when you ^C to exit)
9+
* Fix `reload!` in rails console
910

1011
## 1.1.1
1112

lib/spring/application.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ def preload
9191

9292
require Spring.application_root_path.join("config", "environment")
9393

94+
@original_cache_classes = Rails.application.config.cache_classes
9495
Rails.application.config.cache_classes = false
96+
9597
disconnect_database
9698

9799
@preloaded = :success
@@ -161,9 +163,13 @@ def serve(client)
161163
# Load in the current env vars, except those which *were* changed when spring started
162164
env.each { |k, v| ENV[k] ||= v }
163165

164-
# requiring is faster, and we don't need constant reloading in this process
165-
ActiveSupport::Dependencies.mechanism = :require
166-
Rails.application.config.cache_classes = true
166+
# requiring is faster, so if config.cache_classes was true in
167+
# the environment's config file, then we can respect that from
168+
# here on as we no longer need constant reloading.
169+
if @original_cache_classes
170+
ActiveSupport::Dependencies.mechanism = :require
171+
Rails.application.config.cache_classes = true
172+
end
167173

168174
connect_database
169175
srand

0 commit comments

Comments
 (0)