Sweepers are rails caching constructs that allow changes to models to sweep (clean/remove) cache contents, so keeping the cache entries in sync with data. Sweepers are a combination of observers and controller filters.
Questions tagged [sweeper]
29 questions
10
votes
7 answers
In Rails, a Sweeper isn't getting called in a Model-only setup
I'm working on a Rails app, where I'm using page caching to store static html output. The caching works fine. I'm having trouble expiring the caches, though.
I believe my problem is, in part, because I'm not expiring the cache from my controller.…

charliepark
- 1,480
- 2
- 13
- 15
4
votes
2 answers
How does one include a module with cache expirations in sweepers?
We have the following sweeper in a rails application:
class AgencyEquipmentTypeSweeper < ActionController::Caching::Sweeper
observe AgencyEquipmentType
#include ExpireOptions
def after_update(agency_equipment_type)
…

btelles
- 5,390
- 7
- 46
- 78
4
votes
1 answer
Rails Caching: Using sweepers for actions which require parameters
I'm trying to use sweepers to handle my page refreshes. For refreshing index actions, etc everything works fine...but I can't seem to sweepers to interpret page parameters. If anyone can tell me what's wrong with the code below, I'd be very…

PlankTon
- 12,443
- 16
- 84
- 153
4
votes
2 answers
Action caching is not expiring correctly, even when I can see it's being called
I've got a sweeper that's supposed to expire a few action caches. Even though the debugger stops immediately before the call to expire_action, it's not actually expiring the action. Any idea what could be going on?
Here are the relevant sweeper and…

btelles
- 5,390
- 7
- 46
- 78
3
votes
1 answer
Rails 3.2: Pre-render (bake) a new page cache immediately after expiry?
I have an application that uses caches_page for certain controllers/actions. To expire the cache, I use a sweeper. All in all, it's a standard solution.
However, because some changes may cause a bit of a rush of requests on the server (because push…

Flambino
- 18,507
- 2
- 39
- 58
2
votes
1 answer
Rails: Accessing Controller Variables in a Sweeper
So I have some code here I need to modify regarding a Rails Sweeper:
class UserTrackingSweeper < ActionController::Caching::Sweeper
observe User
def after_update(user)
return if user.nil? || user.created_at.nil? #fix weird bug complaining…

adrian
- 2,326
- 2
- 32
- 48
2
votes
1 answer
Rails 3 caching: How do I use a sweeper with Action and Fragment caching to expire the cache?
I'm working on a page that displays a restaurant menu. I have 2 models: FoodMenu has_many :products and Product belongs_to :food_menu. I don't have controllers for either model. Instead, I am using a "pages_controller.rb" to display each FoodMenu…

monfresh
- 7,974
- 1
- 25
- 22
2
votes
2 answers
How can I access named routes in a Rails sweeper?
I have a sweeper that reheats cache by opening urls in forked processes. It's easy enough to hard-code the host for those urls, but I want it to change dynamically, based on environment.
I know I can set global/environmental variables for this, but…

glortho
- 13,120
- 8
- 49
- 45
2
votes
3 answers
Testing a sweeper with RSpec in Rails
I want to make sure my sweeper is being called as appropriate so I tried adding something like this:
it "should clear the cache" do
@foo = Foo.new(@create_params)
Foo.should_receive(:new).with(@create_params).and_return(@foo)
…

DEfusion
- 5,533
- 5
- 44
- 60
2
votes
1 answer
Can Rails sweepers work across different controllers?
I have action caching working on my Sites index, and set up a SiteSweeper that works fine:
# app/controllers/admin/sites_controller.rb
class Admin::SitesController < Admin::BaseController
cache_sweeper :site_sweeper, :only => [:create, :update,…

jhiro009
- 576
- 4
- 13
2
votes
1 answer
rails - caches_action expire_action
I want to expire a cached action and wondered how to generate the correct reference.
#controller
caches_action :index, :layout => false
#generates this fragment which works fine
views/0.0.0.0:3000/article/someid/posts
#sweeper
...
expire_action…

mark
- 10,316
- 6
- 37
- 58
2
votes
1 answer
Sweeper missing method 'expire_fragment' in rspec
I am using a sweeper to clear a fragment cache and everything is working fine in development, but I am receiving an error in our specs
2) Admin - Categories #index displays all categories
Failure/Error: create_basic_category_set
…

Matt Ramirez
- 673
- 6
- 19
2
votes
0 answers
How to update cached action?
Loosing ideas how to properly use action caching for a controller indirectly depending on a model.
The background scenario:
Having a simple rails model for product objects
class Product < ActiveRecord::Base
...
end
A controller which handles…

David Unric
- 7,421
- 1
- 37
- 65
2
votes
1 answer
Unable to expire_action on Rails
tl;dr
My expire_index method below is getting called, I see the puts in the logs. However, when I refresh the page is the stale version.
note: I am using rails_admin for updating the models. But have also noticed the same behavior using rails…

Matthew Boston
- 1,320
- 10
- 24
2
votes
1 answer
How do I expire home page cache when an article is updated?
I'm attempting to use a sweeper to clear the home page index action when a new article is published.
The home page cache is working fine in development environment and expires after 1 minute. However when an article is saved, the sweeper action is…

Space
- 2,022
- 1
- 19
- 29