Skip to content


Subversion checkout URL

You can clone with
Download ZIP


uninitialized constant ActionController::Caching::Sweeper #3729

jesseclark opened this Issue · 6 comments

7 participants


I'm using rails 3.1.3 and ruby 1.9.2.

Following the Rails Caching Guide I have created a sweeper to clear memcached when related objects get modified.

class MedicalProfileSweeper < ActionController::Caching::Sweeper
  observe MedicalProfile, User, Study

  def expire_cached_content(mp)

  alias_method :after_save, :expire_cached_content
  alias_method :after_destroy, :expire_cached_content


When I try to start the server the app pukes with this error:
/app/sweepers/medical_profile_sweeper.rb:1:in `': uninitialized constant ActionController::Caching::Sweeper (NameError)

I have added app/sweepers to the autoload_paths.
I am not using ActiveRecord in this app and this is how I am requiring the rails libs that I am using:

require "active_resource/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "rails/test_unit/railtie"
require "sprockets/railtie"

Ah so, coming back to look at this issue fresh, I went and looked in actionpack/lib/action_controller/sweeping and noticed that in two places this Module looks checks for the presence of ActiveRecord, most notably the entire Sweeper class definition is wrapped in this check:

    if defined?(ActiveRecord) and defined?(ActiveRecord::Observer)
      class Sweeper < ActiveRecord::Observer #:nodoc:

which I guess makes sense because Sweepers inherit from Observers which is in AR.

It would be really helpful if the ActiveRecord dependency for using Sweepers was mentioned in the Rails Caching Guide and the module documentation.

Luckily, Mongoid has an Observer class so I can still get this functionality implemented.

If I get time soon I will submit a documentation patch.


encountering the same issue. Also using Mongoid. Just noting so that folks don't think it's only Jesse who's having do work around it.


Having the same issue with Mongoid.


@jesseclark Did you have a chance to submit the documentation? Also are you not loading ActiveRecord in your config?



I added documentation, can you please close this issue?


@sgerrand sgerrand referenced this issue from a commit in sgerrand/rails
@schneems schneems Doc: sweepers only work on Active Record Models
In response to this rails issue: rails#3729
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.