Class: Mack::Caching::PageCaching

Inherits:
Object
  • Object
show all
Defined in:
lib/mack-caching/page_caching/page_caching.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Page

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ PageCaching

:nodoc:



7
8
9
# File 'lib/mack-caching/page_caching/page_caching.rb', line 7

def initialize(app) # :nodoc:
  @app = app
end

Instance Method Details

#call(env) ⇒ Object

:nodoc:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mack-caching/page_caching/page_caching.rb', line 11

def call(env) # :nodoc:
  if configatron.mack.caching.use_page_caching
    request = Mack::Request.new(env)
    page = Cachetastic::Caches::PageCache.get(request.fullpath)
    if page
      response = Mack::Response.new
      response["Content-Type"] = page.content_type
      response.write(page.body)
      return response.finish
    end
    ret = @app.call(env)
    unless ret[2].is_a?(Rack::File)
      res = ret[2]
      if res["cache_this_page"] && res.successful?
        Cachetastic::Caches::PageCache.set(request.fullpath, Mack::Caching::PageCaching::Page.new(res.body, res["Content-Type"]))
      end
    end
    return ret
  end
  return @app.call(env)
end