ruby-on-rails - Rails 3.2.4 SQL 查询正在缓存 find 上的结果(:all)

标签 ruby-on-rails caching activerecord scope sqlite3-ruby

我不完全确定这个系统是否正在缓存数据,但它具有一些缓存的特征。

基本上我在搞乱 Rails 3.2.4,系统开始不显示一些结果。我认为这与我放入代码模型中的默认范围有关,但即使如此,这也应该显示所有结果,而不是十分之九。但是,我总是会丢失我创建的新记录以及我之后创建的任何其他记录那个记录。我检查我的 sqlite3 数据库以查看数据是否放置在其中,并检查所有连接信息并确保缓存已关闭。但是,如果我更改任何模型文件或 Controller 文件然后保存它,我就可以显示数据。甚至不需要更改代码,只需触摸命令就可以解决问题。我认为这与范围有关,但我不能完全确定。我发现的一种解决方案就是返回到 Rails 3.2.2。看来能成功。但我还是不喜欢在没有弄清楚这一点的情况下就屈服的感觉。

开发.rb

  # Show full error reports and disable caching
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false 

房子.rb

class House < ActiveRecord::Base
  attr_accessible :name

  default_scope :order => 'created_at DESC', :limit => 50
  validates_presence_of :name
  has_many :roomies
end

架构.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

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

<%= debug @houses %>

正如你所见,没有什么 super 疯狂的。

最佳答案

Rails 3.2.4 对作用域调用的无意缓存进行了回归。请尝试使用 Rails 3.2.5,其中包括 this commit

关于ruby-on-rails - Rails 3.2.4 SQL 查询正在缓存 find 上的结果(:all),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10858923/

相关文章:

ruby-on-rails - 如何在插件的 before_save 回调中包含实例方法?

mysql - ruby ActiveRecord gem 的问题

ruby-on-rails - rails 4 : manipulate link_to remote POST query string parameters

javascript - 补丁 Rails 3 以修复 CSRF 保护漏洞

ruby-on-rails - Rails,生产环境, "Object is not missing constant"

http - 要求浏览器尽可能积极地缓存

react-native - 如何清除 Windows 上的所有 react-native 缓存,文件在哪里?

ruby-on-rails - 带乘客的 Rails 仅在开发中运行

java - Spring可缓存多个节点

PHP ActiveRecord 添加下划线