0
的ActiveRecord的禁用实现QueryCache我想禁用ActiveRecord的红宝石的查询缓存,但它不工作,代码如下:如何从红宝石
def test_transaction
ActiveRecord::Base.connection.execute("create table if not exists t(name varchar(100))")
ActiveRecord::Base.connection.uncached do
begin
ActiveRecord::Base.transaction do
ActiveRecord::Base.connection.execute("insert into t values('one')")
ActiveRecord::Base.connection.execute("insert into t values('two')")
ActiveRecord::Base.connection.execute("insert into t values('three')")
ActiveRecord::Base.connection.execute("insert into t values('four')")
result = ActiveRecord::Base.connection.select_all("select count(*) as total from t")[0]['total'].to_i
assert_equal(0, result)
end
ensure
ActiveRecord::Base.connection.execute("drop table if exists t")
end
end
end
其实无论何时代码运行在选择之前,我通过控制台登录mysql并执行相同的select查询,结果总数为零,所以没关系,但在代码执行select后,结果为4,也就是说select必须从查询缓存,但这是我不打算,所以任何人都可以为我提供任何帮助?
预先感谢您!