Permalink
Browse files

allow AR caches to be cleared, clear them on class reloading

  • Loading branch information...
tenderlove committed Feb 3, 2011
1 parent 082326d commit 7423a71fc02c0ca3bf37b94e16a1322c0caaa6fd
@@ -750,6 +750,12 @@ def reset_column_information
@arel_engine = @relation = nil
end
+ def clear_cache! # :nodoc:
+ @@columns.clear
+ @@columns_hash.clear
+ @@arel_tables.clear
+ end
+
def reset_column_cache # :nodoc:
@@columns.delete table_name
@@columns_hash.delete table_name
@@ -72,6 +72,7 @@ class Railtie < Rails::Railtie
ActiveSupport.on_load(:active_record) do
ActionDispatch::Reloader.to_cleanup do
ActiveRecord::Base.clear_reloadable_connections!
+ ActiveRecord::Base.clear_cache!
end
end
end
@@ -1553,6 +1553,14 @@ def test_compute_type_no_method_error
end
end
+ def test_clear_cache!
+ # preheat cache
+ c1 = Post.columns
+ ActiveRecord::Base.clear_cache!
+ c2 = Post.columns
+ assert_not_equal c1, c2
+ end
+
def test_default_scope_is_reset
Object.const_set :UnloadablePost, Class.new(ActiveRecord::Base)
UnloadablePost.table_name = 'posts'

0 comments on commit 7423a71

Please sign in to comment.