Caching: wrong paths and pages are not expired

466 Views Asked by At

I've got problem with simple caching (ruby 1.9.2, rails 3.1.3, development environment):

development.rb:

    config.action_controller.perform_caching = true
    config.action_controller.cache_store = :file_store, 'tmp/cache'
    config.action_controller.page_cache_directory = 'public/cache'

sweeper:

class CacheSweeper < ActionController::Caching::Sweeper
  observe Article, Photo, Advertisement
  def after_save(record)
    expire_home
  end

...

  private

...

  def expire_home
    expire_page(:controller => '/homes', :action => 'index')
  end

end

controllers:

class HomeController < ApplicationController

  caches_page :index
  cache_sweeper :cache_sweeper

  def index
....

Pages are cached in right directory and actions triggers sweeper actions as they should, but pages are not expired and server is trying to get cached pages from default place.

cache: [GET /] miss

Any ideas why? Is there something wrong with my configuration?

2

There are 2 best solutions below

1
dmcnally On

You have the wrong controller name and leading slash. Try the following:

def expire_home
  expire_page(:controller => 'home', :action => 'index')
end
1
davydotcom On

expire_page expects the path of the route so for example the root url in a caches page you could do

expire_page "/"

Also, to get your web server to look into the right place you need to configure a rewrite rule in apache or nginx to look in the cache directory.