Sha256: 3f2ffa771e73f54b25bbb990dae9cde0fdb0e2cef756d501d4d6f0f382d98e44

Contents?: true

Size: 1.19 KB

Versions: 5

Compression:

Stored size: 1.19 KB

Contents

module Padrino
  module Cache
    module Helpers
      module Page
        def expires_in(time)
          @_last_expires_in = time
        end

        def self.padrino_route_added(route, verb, path, args, options, block)
          if route.cache and %w(GET HEAD).include?(verb)
            route.add_before_filter(Proc.new {
              if self.class.caching?
                value = self.class.cache_store.get(route.cache.respond_to?(:call) ? route.cache.call(request) : env['PATH_INFO'])
                halt 200, value if value
              end
            })
            route.add_after_filter(Proc.new { |something|
              if self.class.caching?
                if @_last_expires_in
                  self.class.cache_store.set(route.cache.respond_to?(:call) ? route.cache.call(request) : env['PATH_INFO'], @_response_buffer, :expires_in => @_last_expires_in)
                  @_last_expires_in = nil
                else
                  self.class.cache_store.set(route.cache.respond_to?(:call) ? route.cache.call(request) : env['PATH_INFO'], @_response_buffer)
                end
              end
            })
          end
        end
      end # Page
    end # Helpers
  end # Cache
end # Padrino

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
padrino-cache-0.9.24 lib/padrino-cache/helpers/page.rb
padrino-cache-0.9.23 lib/padrino-cache/helpers/page.rb
padrino-cache-0.9.22 lib/padrino-cache/helpers/page.rb
padrino-cache-0.9.21 lib/padrino-cache/helpers/page.rb
padrino-cache-0.9.20 lib/padrino-cache/helpers/page.rb