How to prevent rails from caching Model.all query

I don't understand why in development mode, the query is getting cached even after inserting a new record. What I mean is that, after creating a new record, my Model.all doesn't pull that record from the db. I checked with IRB and the record is persisted. Once I restart the server, the new record shows up.

Here is the detail...

  • all environment configs are standard ones generated by "rails new app"

First time after starting the server, when i hit the pagecontroller#index, the logs are

Processing by PagesController#index as HTML
  Page Load (14.9ms)  SELECT "pages".* FROM "pages" 
  Rendered pages/index.html.erb within layouts/application (4.1ms)
Completed 200 OK in 237ms (Views: 167.5ms | ActiveRecord: 16.9ms)

After creating a page, user gets redirected to index action and the logs are

Started GET "/pages" for 127.0.0.1 at 2012-06-13 09:40:27 -0400
 Processing by PagesController#index as HTML
 Rendered pages/index.html.erb within layouts/application (1.6ms)
Completed 200 OK in 5ms (Views: 5.2ms | ActiveRecord: 0.0ms)

My action

def index
  @pages = Page.all
end

def create
  @page = Page.new(params[:page])
  if @page.save
    flash[:notice] = "Page saved Successfully"
    redirect_to :action => "index"
  else
    flash[:alert] = "Errors on saving the page"
    render :action => "new"
  end
end

I am pretty new to rails and couldn't find anything in my research of the problem. Can someone help me.

GEMS

  • actionmailer (3.2.4)
  • actionpack (3.2.4)
  • activemodel (3.2.4)
  • activerecord (3.2.4)
  • activeresource (3.2.4)
  • activesupport (3.2.4)
  • arel (3.0.2)
  • bcrypt-ruby (3.0.0)
  • builder (3.0.0)
  • bundler (1.1.4)
  • ci_reporter (1.7.0)
  • coffee-rails (3.2.1)
  • coffee-script (2.2.0)
  • coffee-script-source (1.3.3)
  • erubis (2.7.0)
  • execjs (1.4.0)
  • hike (1.2.1)
  • i18n (0.6.0)
  • journey (1.0.3)
  • json (1.7.3)
  • libv8 (3.3.10.4 x86_64-darwin-11)
  • mail (2.4.4)
  • metaclass (0.0.1)
  • mime-types (1.18)
  • mocha (0.11.4)
  • multi_json (1.3.6)
  • mynyml-redgreen (0.7.1)
  • polyglot (0.3.3)
  • rack (1.4.1)
  • rack-cache (1.2)
  • rack-ssl (1.3.2)
  • rack-test (0.6.1)
  • rails (3.2.4)
  • railties (3.2.4)
  • rake (0.9.2.2)
  • rdoc (3.12)
  • rubygems-bundler (1.0.2)
  • rvm (1.11.3.3)
  • sass (3.1.19)
  • sass-rails (3.2.3)
  • sprockets (2.1.3)
  • sqlite3 (1.3.6)
  • term-ansicolor (1.0.7)
  • therubyracer (0.10.1)
  • thor (0.15.2)
  • tilt (1.3.3)
  • tinymce-rails (3.5)
  • treetop (1.4.10)
  • tzinfo (0.3.33)
  • uglifier (1.0.3)

Answers


Rails 3.2.4 had an issue with caching findall. I suggest you upgrade to a newer version of Rails, as per this question: Rails 3.2.4 SQL query is caching results on find(:all)


Need Your Help

SharePoint blog posts have empty category when accessing via WCF

c# linq wcf sharepoint sharepoint-2010

I have a c# MVC app that is accessing SharePoint blog data via the /_vti_bin/ListData.svc service reference. I am able to successfully get all the PostsItems as well as all the CategoriesItems. How...

ListView feeded with more adapters acording to need

java android listview android-listview android-arrayadapter

I'm pretty much new in Android coding. I have simple app where there is, amongst other views, a ListView.