lib/nitro/caching/output.rb in nitro-0.17.0 vs lib/nitro/caching/output.rb in nitro-0.18.0
- old
+ new
@@ -1,9 +1,5 @@
-# * George Moschovitis <gm@navel.gr>
-# (c) 2004-2005 Navel, all rights reserved.
-# $Id: output.rb 9 2005-04-13 00:08:20Z nasis $
-
require 'fileutils'
module Nitro
# Adds support for caching.
@@ -32,41 +28,52 @@
end
# Enable output caching for the given actions.
def cache_output(*actions)
- return unless caching_enabled
+ return unless (caching_enabled and Caching.caching_enabled)
str = actions.collect { |a| ":#{a}" }.join(', ')
module_eval %{
- after_filter "do_cache_output", :only => [ #{str} ]
+ post "do_cache_output", :only => [ #{str} ]
}
end
private
def output_cache_path(path)
- filename = ((path.empty? || path == '/') ? '/index' : path)
- filename << '.html' unless (name.split('/').last || name).include? '.'
- return output_cache_root + filename
+ filename = ((path.empty? || path == '/') ? '/index' : path.dup)
+# filename.gsub!(/\/$/, '')
+ filename << 'index.html' unless (name.split('/').last || name).include? '.'
+ return output_cache_root + '/' + filename
end
end
private
def do_cache_output
- if caching_enabled and caching_allowed?
- self.class.do_cache_output(@request.path, @out)
+ if caching_enabled and Caching.caching_enabled and caching_allowed?
+ self.class.do_cache_output(@request.uri, @out)
end
end
+ def expire_output(name)
+ begin
+ FileUtils.rm("#{context.dispatcher.public_root}/#{name}/index.html")
+ rescue Object
+ # gmosx: is this the right thing to do?
+ end
+ end
+
def caching_allowed?
!@request.post?
end
end
end
end
+
+# * George Moschovitis <gm@navel.gr>