Module: Nitro::Caching::Output::ClassMethods

Defined in:
lib/nitro/caching/output.rb

Instance Method Summary collapse

Instance Method Details

#cache_output(*actions) ⇒ Object

Enable output caching for the given actions.



40
41
42
43
44
45
46
47
48
# File 'lib/nitro/caching/output.rb', line 40

def cache_output(*actions)
  return unless caching_enabled?

  str = actions.collect { |a| ":#{a}" }.join(', ')

  module_eval %{
    after "do_cache_output", :on => [ #{str} ]
  }
end

#do_cache_output(path, content) ⇒ Object



31
32
33
34
35
36
# File 'lib/nitro/caching/output.rb', line 31

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