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 7883167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:27:43+00:00 2026-06-03T04:27:43+00:00

I have the following setup: A model called Categories. These categories are managed using

  • 0

I have the following setup: A model called Categories. These categories are managed using ActiveAdmin. I want to cache the categories using page caching.

This is how I’ve setup my app/admin/categories.rb

ActiveAdmin.register Category do
    controller do 
        cache_sweeper :category_sweeper
    end
end

This is my sweeper:

class CategorySweeper < ActionController::Caching::Sweeper
  observe Category

  def after_save(category)
    expire_cache(category)
  end

  def after_destroy(category)
    expire_cache(category)
  end

  def expire_cache(category)
    expire_page :controller => 'categories', :action => 'index', :format => 'json'
  end
end

And here is my controller:

class CategoriesController < ApplicationController
    caches_page :index
  cache_sweeper :category_sweeper

    respond_to :json

    def index
      @categories = Category.all 
      respond_with(@categories)
    end

    def show
      CategorySweeper.instance.expire_cache(@category)
      respond_with('manually sweeped!')
    end
end

So the idea is when there is a change in the active admin the sweeper should get invoked. I set up debug.log and turns out it’s working. But for some reason the cache does not expire!

But, if I do the show action (i.e. go to /categories/1.json then my manual sweeper kicks in and it works fine). So why is the sweeper only working when I invoke it and not when there is a change in the admin?

Thanks in advance,
-David

  • 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-06-03T04:27:44+00:00Added an answer on June 3, 2026 at 4:27 am

    Your ActiveAdmin controller located in different namespace, see this SO question.

    Shortly:

    Add slash into cache expiration url code:

    def expire_cache(category)
      expire_page :controller => '/categories', :action => 'index', :format => 'json'
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following model setup - a User is interested in projects in
I have following models setup in my Django application class School(models.Model): name = models.TextField()
i have the following models setup class Player(models.Model): #slug = models.slugField(max_length=200) Player_Name = models.CharField(max_length=100)
I have this following setup, a textarea named with some data in it that
I have the following model in django: class Node(models.Model): name = models.CharField(max_length=255) And this
I have the following model setup. from django.db import models from django.contrib.auth.models import User
I have following setup, but when I put 1024 and replace all 512 with
I have the following setup: Code on my local machine (OS X) shared as
I have the following setup, and I need to know how to persist state.
I have the following setup, and the empty view text doesn't show up... protected

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.