Sha256: ae1ee50c41771f31458d5a20e61b39a5ee49aa6a123fee60b3ad7e276be0a0bd

Contents?: true

Size: 887 Bytes

Versions: 15

Compression:

Stored size: 887 Bytes

Contents

module TrustyCms
  class PageResponseCacheDirector
    def initialize(page, listener)
      @page = page
      @listener = listener
    end

    def set_cache_control
      cacheable? ? cacheable_response : non_cacheable_response
    end

    class << self
      def cache_timeout
        @cache_timeout ||= 5.minutes
      end

      def cache_timeout=(val)
        @cache_timeout = val
      end
    end

    private

    def non_cacheable_response
      @listener.set_expiry nil, :private => true, "no-cache" => true
      @listener.set_etag('')
    end

    def cacheable_response
      timeout = self.class.cache_timeout
      if @page.respond_to?(:cache_timeout)
        timeout = @page.cache_timeout
      end

      @listener.set_expiry timeout, :public => true, :private => false
    end

    def cacheable?
      @listener.cacheable_request? && @page.cache?
    end

  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
trusty-cms-4.1.2 app/models/trusty_cms/page_response_cache_director.rb
trusty-cms-4.1.1 app/models/trusty_cms/page_response_cache_director.rb
trusty-cms-4.1.0 app/models/trusty_cms/page_response_cache_director.rb
trusty-cms-4.0.2 app/models/trusty_cms/page_response_cache_director.rb
trusty-cms-3.9.7 app/models/trusty_cms/page_response_cache_director.rb
trusty-cms-3.9.6 app/models/trusty_cms/page_response_cache_director.rb
trusty-cms-3.9.5 app/models/trusty_cms/page_response_cache_director.rb
trusty-cms-4.0.1 app/models/trusty_cms/page_response_cache_director.rb
trusty-cms-3.9.4 app/models/trusty_cms/page_response_cache_director.rb
trusty-cms-3.9.3 app/models/trusty_cms/page_response_cache_director.rb
trusty-cms-3.9.2 app/models/trusty_cms/page_response_cache_director.rb
trusty-cms-4.0.0 app/models/trusty_cms/page_response_cache_director.rb
trusty-cms-3.9.1 app/models/trusty_cms/page_response_cache_director.rb
trusty-cms-3.9.0 app/models/trusty_cms/page_response_cache_director.rb
trusty-cms-3.8.4 app/models/trusty_cms/page_response_cache_director.rb