lib/nitro/caching/output.rb in nitro-0.20.0 vs lib/nitro/caching/output.rb in nitro-0.21.0
- old
+ new
@@ -4,74 +4,74 @@
# Adds support for caching.
module Caching
- # Output caching.
+ # Output caching.
- module Output
+ module Output
- def self.append_features(base) # :nodoc:
- super
- base.extend(ClassMethods)
- base.module_eval do
- cattr_accessor :output_cache_root, 'public'
- end
- end
+ def self.append_features(base) # :nodoc:
+ super
+ base.extend(ClassMethods)
+ base.module_eval do
+ cattr_accessor :output_cache_root, 'public'
+ end
+ end
- module ClassMethods
+ module ClassMethods
- def do_cache_output(path, content)
- filepath = output_cache_path(path)
- FileUtils.makedirs(File.dirname(filepath))
- File.open(filepath, 'w+') { |f| f.write(content) }
- Logger.debug "Cached page: #{filepath}" if $DBG
- end
+ def do_cache_output(path, content)
+ filepath = output_cache_path(path)
+ FileUtils.makedirs(File.dirname(filepath))
+ File.open(filepath, 'w+') { |f| f.write(content) }
+ Logger.debug "Cached page: #{filepath}" if $DBG
+ end
- # Enable output caching for the given actions.
+ # Enable output caching for the given actions.
- def cache_output(*actions)
- return unless caching_enabled?
+ def cache_output(*actions)
+ return unless caching_enabled?
- str = actions.collect { |a| ":#{a}" }.join(', ')
+ str = actions.collect { |a| ":#{a}" }.join(', ')
- module_eval %{
- post "do_cache_output", :only => [ #{str} ]
- }
- end
+ module_eval %{
+ post "do_cache_output", :only => [ #{str} ]
+ }
+ end
- private
+ private
- def output_cache_path(path)
- 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
+ def output_cache_path(path)
+ 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
+ private
- def do_cache_output
- if caching_enabled? and caching_allowed?
- self.class.do_cache_output(@request.uri, @out)
- end
- end
+ def do_cache_output
+ if 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
+ 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
end