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.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/nitro/caching/output.rb', line 58

def cache_output(*actions)
  return unless caching_enabled?

  # keep track of cached actions.
  for a in actions        
    Nitro::Caching::Output.cached_actions << [self, a]
  end
  
  str = actions.collect { |a| ":#{a}" }.join(', ')

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

#do_cache_output(path, content) ⇒ Object



49
50
51
52
53
54
# File 'lib/nitro/caching/output.rb', line 49

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