Topic: Cache Sweeper Doesn't Like Me

I got Apache to serve up files from my cache directory...its amazing how much faster things zip by now.

The problem is whenever I try to sweep my cache. I get permissions errors even though my cache directory to 757

http://pastie.caboo.se/62112

class ArticleSweeper < ActionController::Caching::Sweeper
  observe Article
 
  def after_save(cache)
    expire_cache(cache)
  end
 
  def after_destroy(cache)
    expire_cache(cache)
  end
         
  private
 
  def expire_cache(cache)
    expire_page(:controller => 'articles', :action => 'index')   
    expire_page(:controller => 'articles', :action => 'show', :id => cache)
  end
end

Re: Cache Sweeper Doesn't Like Me

pimpmaster wrote:

The problem is whenever I try to sweep my cache. I get permissions errors even though my cache directory to 757

How about the individual files inside the cache directory, what permission settings do those have? Since Ruby is creating the files, you would think i would have permission to destroy them as well. Hmm.

Railscasts - Free Ruby on Rails Screencasts

Re: Cache Sweeper Doesn't Like Me

Bingo ryan,

For some reason my permissions are set to 644 on the contained files. How can I change this?

Re: Cache Sweeper Doesn't Like Me

"chmod +w wherever_your_files_are/*" should do it.  if it doesn't, you can specify the full permissions code:
"chmod 666 wherever/*"
make sure not to apply 666 to the directory itself though - that turns things evil.

Re: Cache Sweeper Doesn't Like Me

I must be doing something wrong in my code because my cachesfile is not getting swept. Here is the controller code

class ArticlesController < ApplicationController
  caches_page :index
  cache_sweeper :article_sweeper, :only => [:create, :edit, :new, :update, :destroy]
...

I also have a "sweeper" folder to keep my controller dir clean. I have put this line in environment.rb

config.load_paths += %W( #{RAILS_ROOT}/app/sweepers/ )
config.action_controller.page_cache_directory = RAILS_ROOT + "/public/cache"

Any ideas?

Re: Cache Sweeper Doesn't Like Me

Well I dont understand it... now I cant cache at all! Using the same code as above, I get this lovely message

Errno::EACCES (Permission denied - /var/www/apps/kc/current/config/../public/cache/articles.html):
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/caching.rb:90:in `initialize'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/caching.rb:90:in `cache_page'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:30:in `benchm
ark'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/caching.rb:88:in `cache_page'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/caching.rb:133:in `cache_page
'
    (eval):1:in `caches_page'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:462:in `call'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:450:in `call'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:637:in `call_filte
r'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:619:in `perform_ac
tion_without_benchmark'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in `perfor
m_action_without_rescue'
    /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in `perfor
m_action_without_rescue'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/rescue.rb:83:in `perform_acti
on'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:in `process_witho
ut_filters'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:624:in `process_wi
thout_session_management_support'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/session_management.rb:114:in
`process'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:330:in `process'
    /usr/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in `dispatch'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:78:in `process'
    /usr/lib/ruby/1.8/thread.rb:135:in `synchronize'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in `process'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:618:in `process_client'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in `process_client'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:271:in `run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in `run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:127:in `run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb:211:in `run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:243
    /usr/bin/mongrel_rails:16