Rails的3.2.4 SQL查询结果的缓存上查找(:所有) [英] Rails 3.2.4 SQL query is caching results on find(:all)
问题描述
我总不知道,如果这个系统缓存中的数据,但它有一些缓存的退化特征的研究。
I not total sure if this system is caching the data but it has some of the charcteristics of caching.
Basicly我是梅辛与导轨3.2.4,系统启动不显示的一些结果。我认为这是露到默认的范围,我投入了code模型,但即便如此,这应该显示所有的结果不是9出10。不过,我会永远丢失了我创造的新纪录和任何其他记录中我该记录后创建。我检查我的sqlite3的数据库,看数据是发生在那里,也随着确保缓存检查所有的连接信息是关闭的。不过,我可以得到的数据显示,如果我换了任何模型文件或控制文件,然后将其保存。甚至不会改变code只是touch命令就可以做到。我认为这是与范围,但我不能总肯定。一个解决方案,我发现仅仅是回落到Rails的3.2.2去。它接缝做的伎俩。但我还是不喜欢砍伐就像我刚才给同出搞清楚了这一点。
Basicly I was messing with rails 3.2.4 and the system started to not display some of the results. I think this is dew to the default scope I put into the code model but even so this should display all the results not 9 out of 10. However I would always be missing the new records that I created and any other records that I create after that record. I check my sqlite3 database to see if the data was place in there and also check all the connection information along with making sure caching is off. However I could get the data to show up if I changed the any model file or controller file and then saved it. Would not even change the code just the touch command would do the trick. I think it has something to do with scope but I can't be total sure. One solution I found is just to go back down to Rails 3.2.2. It seams to do the trick. But I still don't like felling like I just gave in with out figuring this out.
development.rb
development.rb
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
house.rb
house.rb
class House < ActiveRecord::Base
attr_accessible :name
default_scope :order => 'created_at DESC', :limit => 50
validates_presence_of :name
has_many :roomies
end
schema.rb
schema.rb
ActiveRecord::Schema.define(:version => 20120601204050) do
create_table "houses", :force => true do |t|
t.string "name"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
end
houses_controller.rb
houses_controller.rb
class HousesController < ApplicationController
def index
@houses = House.all
end
def new
@house = House.new
end
def show
@house = House.find(params[:id])
end
def create
@house = House.new(params[:house])
if @house.save
flash[:success] = "Your house has been created and is ready to have people added to it."
redirect_to houses_path
else
flash[:error] = "Your house could not be added dew to a error!"
render :action => :new
end
end
end
房子/ index.html.erb
houses/index.html.erb
<%= debug @houses %>
正如你可以看到什么超级疯狂。
As you can see nothing super crazy.
推荐答案
的Rails 3.2.4不得不四处范围的呼叫无意缓存回归。尝试轨3.2.5代替,其中包括这次提交
Rails 3.2.4 had a regression around unintentional caching of calls made to scopes. Try rails 3.2.5 instead, which includes this commit
这篇关于Rails的3.2.4 SQL查询结果的缓存上查找(:所有)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!