Sha256: 5f40f9719c3d4dac675e82552baf53c48f65c86ef486e09efab63c63de0d5657

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

module NetworkExecutive
  class GuideController < NetworkExecutive::ApplicationController

    respond_to :html, :json

    cattr_accessor :index_cached

    def index
      if stale_cache?
        self.class.index_cached = true

        @guide = Guide.new
      end
    end

  private

    # Only 304 if the cache is fresh *OR* we haven't cached the page yet.
    # This allows server reboots to regenerate the content in the case
    # of an error.
    #
    # NOTE: It is important to note the order of the arguments. The call to
    # Rails` `stale?` method does magical things to the response, so its
    # important that it comes last. If the custom logic indicates that the
    # page should not be cached, then we don't want the Rails method to be
    # called and magically send an unwanted 304.
    def stale_cache?
      !self.class.index_cached || stale?( caching_params )
    end

    def caching_params
      current_time_slot = Time.now.floor( Guide::Interval.minutes )

      {
        last_modified: current_time_slot,
        etag:          current_time_slot.to_i
      }
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
network_executive-0.0.8 app/controllers/network_executive/guide_controller.rb
network_executive-0.0.7 app/controllers/network_executive/guide_controller.rb