Class: Mongrel::PageCacheHandler::Cacher

Inherits:
HttpHandler
  • Object
show all
Defined in:
lib/cacher.rb

Instance Method Summary collapse

Instance Method Details

#process(request, response) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/cacher.rb', line 6

def process(request, response)
  Mongrel::PageCacheHandler::Utils.do_work(request, response) do
    if response.status == 200
      sent = response.header.instance_variable_get("@sent")
      mcm = sent["mongrel_cache_me"]
      imcm = (sent["ignore_mongrel_cache_me"] || false)
      if mcm && !imcm
        case app_config.page_cache_storage
        when "cachetastic"
          # file_path = Mongrel::PageCacheHandler::Utils.build_full_file_path(request, true)
          file_path = Mongrel::PageCacheHandler::Utils.build_cachetastic_key(request)
          puts "Let's cache this page: #{file_path} to the cache"
          Cachetastic::Caches::PageCache.set(file_path, response.body.string)
        when "disk"
          file_path = Mongrel::PageCacheHandler::Utils.build_full_file_path(request, true)
          puts "Let's cache this page: #{file_path} to the disk"
          File.open(file_path, "w") do |f|
            f.puts response.body.string
          end
        end
      end
    end
  end
end