Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3669630
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:16:00+00:00 2026-05-19T02:16:00+00:00

I want to expire fragments with a sweeper. The sweeper callbacks are executed, but

  • 0

I want to expire fragments with a sweeper. The sweeper callbacks are executed, but the calls to expire_fragment do nothing, because (I assume) cache_configured? returns nil. Caching is configured and fragments are being created and used in my templates (verified it in the logs). What am I doing wrong?

application.rb

config.cache_store = :mem_cache_store, "XXX.XXX.XXX.XXX", { # I use a real IP
    :compress => true,
    :namespace => "#{Rails.env}_r3"
  }
config.active_record.observers = [:auction_sweeper, :address_sweeper]

production.rb

config.action_controller.perform_caching = true

auction_sweeper.rb

class AuctionSweeper < ActionController::Caching::Sweeper 
  observe Auction

  def after_create(auction)
    Rails.logger.info "AuctionSweeper.expire_details #{auction.id} #{cache_configured?.inspect}=#{perform_caching.inspect}&&#{cache_store.inspect}"
    expire_fragment("auction/#{auction.reference_sid}")
  end
end

In log files, cache_configured? is nil and so is perform_caching and cache_store.

AuctionSweeper.expire_details 12732 nil=nil&&nil

So I assume, that my fragments are not expired because the code of expire_fragment reads:

File actionpack/lib/action_controller/caching/fragments.rb, line 87

87:       def expire_fragment(key, options = nil)
88:         return unless cache_configured?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T02:16:01+00:00Added an answer on May 19, 2026 at 2:16 am

    I found a solution (hack?) here that suggests to set @controller and it works for me.

    class AuctionSweeper < ActionController::Caching::Sweeper 
      observe Auction
    
      def after_create(auction)
        @controller ||= ActionController::Base.new
        Rails.logger.info "AuctionSweeper.expire_details #{auction.id} #{cache_configured?.inspect}=#{perform_caching.inspect}&&#{cache_store.inspect}"
        expire_fragment("auction/#{auction.reference_sid}")
      end
    end
    

    Also a note to myself: remember to return true from before filters also in sweepers or you get ActiveRecord::RecordNotSaved and wonder why.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to add expire TIMESTAMP in DB table. I have one field timestamp
I want to make a table where the entries expire 24 hours after they
I want to put the user password check to never expire. When I create
I want to expire a cached action and wondered how to generate the correct
I want to expire my previous page when end user clicks on LogOut or
I want to expire users' passwords on an individual basis in Microsoft Active directory
I am building a asp.net mvc application. I want session to never expire, once
I want my CSS and JS files to expire in the distant future. Can
I want my asp.net mvc(C#) application to be with the session without expire. The
I'm exploring Sinatra and I want to use sessions but I don't want them

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.