我嘗試使用操作緩存來緩存操作,然後使用另一個稱爲刷新的操作手動將其過期。我知道Rails的最佳做法是使用清掃器,但這也不起作用。這在WebBrick本地運行良好,但是當我使用Phusion Passenger部署到Apache時,我無法使緩存過期。看起來,expire_action通過從緩存路徑中省略索引來過期錯誤的操作。expire_action在部署到Apache時不起作用
bills_controller.rb
class BillsController < ApplicationController
caches_action :index
def index
...
end
def refresh
expire_action :action => :index
redirect_to :action => :index
end
當我瀏覽到http://www.mysite.org/bills,/log/production.log表明這一點:
Started GET "/bills"
Rendered bills/index.html.erb
Write fragment views/www.mysite.org/bills/index
然後,當我瀏覽到http://www.mysite.org/refresh,/日誌/production.log顯示了這個:
Started GET "/bills/refresh"
Expire fragment views/www.mysite.org/bills <<<<Culprit?
Redirected to http://www.mysite.org/bills
Started GET "/bills"
Read fragment views/www.mysite.org/bills/index
請注意,Expire fragment views/www.mysite.org/bills不包含/ index部分。我懷疑這是緩存沒有過期的原因,但我不確定。
我的網站Apache的配置是這樣的:
<VirtualHost *:80>
ServerName www.mysite.org
DocumentRoot /var/www/html/mysite.org/public
<Directory /var/www/html/mysite.org/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>