This project is archived and is in readonly mode.

#1961 ✓stale
Gravis

Allow sweepers to run expire_fragment without declaring cache_sweeper

Reported by Gravis | February 13th, 2009 @ 02:59 PM | in 3.x

Hi,

I've tried to find a ticket related to this issue, and didn't find any, sorry if it has been discussed here before. Ok, here's my problem :

I have an activity feed on my site. I'd like to fragment_cache it. The problem occurs when I want to invalid the cache when a new entry is created. I've setup a sweeper, declared it as an observer.

in the sweeper's after_create, I have :


def after_create
  puts("Here I am")
  expire_fragment(:controller => :last_activities, :action => :index, :locale => I18n.locale)
end

When a new entry is created, I can see the "Here I am" output, and expire_fragment will do nothing, silently. I've found some topics in forums saying that only a cache_sweeper in a controller can fire this. That's 100% true. My problem is now to retreive which controllers may create an entry, looking for some observed models before to investigate. This is painful and error-prone, since I will certainly forget a controller.

Would it be possible to have sweepers fire this method (I really don't see the link with a controller here)

Thanks a lot Gravis

Comments and changes to this ticket

  • Marcel Jackwerth

    Marcel Jackwerth April 12th, 2009 @ 12:57 AM

    Just ran across the same problem - most websites are describing how to use the Sweeper as an observer (which makes sense, since @@@class Sweeper < ActiveRecord::Observer@@@) but additionally the Sweeper requires a request which went through a controller before hand. It's definately not intuitive. Workers and other deamons (which do not rely on a controller) won't be able to swipe the caches.

    I use the following workaround in my Sweepers to make them cache-aware. Works with 2.3.2 but might cause issues sooner or later.

    
      delegate :cache_configured?, :cache_store, :to => ActionController::Base
      def perform_action; true; end
      def render; true; end
    
      def self.logger
        ActionController::Base.logger
      end
    
      include ActionController::Benchmarking
      include ActionController::Caching::Fragments
    

    I wouldn't use these Sweepers in your controllers then anymore.

  • Jeremy Kemper

    Jeremy Kemper May 4th, 2010 @ 06:48 PM

    • Milestone changed from 2.x to 3.x
  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:41 PM

    • State changed from “new” to “open”
    • Importance changed from “” to “”

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:41 PM

    • State changed from “open” to “stale”
  • klkk

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages