If you use static rail caching and serve through apache, simply using the explicit xml extension on the URL, you will do it.
if you use only xml and html, you can also edit apache conf by default instead of xml instead of xtml when looking for cached files.
- , , .
, , rails:
,
class XmlThingController < ApplicationController
caches_page :index, :show, :other_actions
/, , xmls:
class Admin::SomeCrudController < AppplicationController
cache_sweeper :stupid_master_sweeper, :only => [ :save, :destroy ]
'config/environment/production.rb'
config.action_controller.page_cache_directory =
File.join(RAILS_ROOT, 'public', 'cache')
- vhost apache conf:
RewriteRule ^/cache - [F,L]
RewriteCond %{DOCUMENT_ROOT}/cache/index.html -f
RewriteRule ^/?$ /cache/index.html [L]
RewriteCond %{DOCUMENT_ROOT}/cache%{REQUEST_URI} -f
RewriteRule ^(.*)$ /cache$1 [L]
RewriteCond %{DOCUMENT_ROOT}/cache%{REQUEST_URI}.html -f
RewriteRule ^(.*)$ /cache$1.html [L]
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://your-website-proxy%{REQUEST_URI} [P,QSA,L]
, :
class StupidMasterSweeper < ActiveRecord::Observer
observe Foo, Bar
def after_save(record); end
def after_destroy(record); end
def filter(controller)
`cd #{RAILS_ROOT} && RAILS_ENV=#{ENV['RAILS_ENV']} rake cache:clear`
end
end
lib/tasks/cache.rake
namespace :cache do
desc "Remove all cached files"
task :clear do
puts `rm -rf #{RAILS_ROOT}/public/cache/*`
end
end
xml, 1.4.2 :
RewriteCond %{DOCUMENT_ROOT}/cache%{REQUEST_URI}.html -f
RewriteRule ^(.*)$ /cache$1.html [L]
RewriteCond %{DOCUMENT_ROOT}/cache%{REQUEST_URI}.xml -f
RewriteRule ^(.*)$ /cache$1.xml [L]