我有一個相同的Rails應用程序與許多域名和輕微的用戶界面差異。每個域可能有不同的區域設置(en,es,fr等)。Rails頁面緩存與不同的域指向相同的應用程序
我用caches_page
來緩存控制器的所有對象。我嘗試了this solution,並對其進行了小修改,以處理域和區域設置而不是子域。
def self.page_cache_path(path,extension)
MyApp::Application.config.action_controller.page_cache_directory + '/cache' + @root_site.to_s + "/" + path + extension
end
def cache_page(content = nil, options = nil, gzip = Zlib::BEST_COMPRESSION)
path = [@root_site, I18n.locale].join("/") # nil would add slash to 2 ends
path << case options
when Hash
url_for(options.merge(:only_path => true, :skip_relative_url_root => true, :format => params[:format]))
when String
options
else
if request.path.empty? || request.path == '/'
'/index'
else
request.path
end
end
super(content, path, gzip)
end
此代碼似乎是寫緩存文件罰款,將域名作爲第一個文件夾:
Write page /Users/user/Sites/myapp/public/cache/domain1.com/en/users/john.html (1.7ms)
Completed 200 OK
我看到的問題是,當我訪問任何緩存不會檢索緩存頁:
Started GET "https://stackoverflow.com/users/john" for 127.0.0.1 at 2013-01-16 19:04:18 -0200
Processing by UsersController#show as HTML
...
Write page /Users/user/Sites/myapp/public/cache/domain1.com/en/users/john.html (1.7ms)
Completed 200 OK
在我users
控制我只是這個
caches_page :show
任何人都知道什麼是阻止從緩存文件中讀取以及如何解決它?