Sha256: 38ac592619e9406fa81697afca6303bc8d00914fde63d57d073397ae1d453feb

Contents?: true

Size: 1.72 KB

Versions: 76

Compression:

Stored size: 1.72 KB

Contents

module YARD
  module Server
    # Implements static caching for requests.
    #
    # @see Router Router documentation for "Caching"
    module StaticCaching
      # Called by a router to return the cached object. By default, this
      # method performs disk-based caching. To perform other forms of caching,
      # implement your own +#check_static_cache+ method and mix the module into
      # the Router class.
      #
      # Note that caching does not occur here. This method simply checks for
      # the existence of cached data. To actually cache a response, see
      # {Commands::Base#cache}.
      #
      # @example Implementing In-Memory Cache Checking
      #   module MemoryCaching
      #     def check_static_cache
      #       # $memory_cache is filled by {Commands::Base#cache}
      #       cached_data = $memory_cache[request.path]
      #       if cached_data
      #         [200, {'Content-Type' => 'text/html'}, [cached_data]]
      #       else
      #         nil
      #       end
      #     end
      #   end
      #
      #   class YARD::Server::Router; include MemoryCaching; end
      # @return [Array(Numeric,Hash,Array)] the Rack-style response
      # @return [nil] if no cache is available and routing should continue
      # @see Commands::Base#cache
      def check_static_cache
        return nil unless adapter.document_root
        cache_path = File.join(adapter.document_root, request.path.sub(/\.html$/, '') + '.html')
        cache_path = cache_path.sub(%r{/\.html$}, '.html')
        if File.file?(cache_path)
          log.debug "Loading cache from disk: #{cache_path}"
          return [200, {'Content-Type' => 'text/html'}, [File.read_binary(cache_path)]]
        end
        nil
      end
    end
  end
end

Version data entries

76 entries across 59 versions & 8 rubygems

Version Path
climine-0.0.2 vendor/bundle/ruby/2.0.0/gems/yard-0.8.7.3/lib/yard/server/static_caching.rb
climine-0.0.1 vendor/bundle/ruby/2.0.0/gems/yard-0.8.7.3/lib/yard/server/static_caching.rb
yard-0.8.7.3 lib/yard/server/static_caching.rb
yard-0.8.7.2 lib/yard/server/static_caching.rb
candlepin-api-0.4.0 bundle/ruby/gems/yard-0.8.7/lib/yard/server/static_caching.rb
candlepin-api-0.4.0 bundle/ruby/1.9.1/gems/yard-0.8.7/lib/yard/server/static_caching.rb
candlepin-api-0.4.0 bundle/ruby/1.8/gems/yard-0.8.7/lib/yard/server/static_caching.rb
yard-0.8.7.1 lib/yard/server/static_caching.rb
yard-0.8.7 lib/yard/server/static_caching.rb
challah-1.0.0 vendor/bundle/gems/yard-0.8.6.1/lib/yard/server/static_caching.rb
yard-0.8.6.2 lib/yard/server/static_caching.rb
challah-1.0.0.beta3 vendor/bundle/gems/yard-0.8.6.1/lib/yard/server/static_caching.rb
challah-1.0.0.beta3 vendor/bundle/gems/yard-0.8.6/lib/yard/server/static_caching.rb
challah-1.0.0.beta3 vendor/bundle/gems/yard-0.8.5.2/lib/yard/server/static_caching.rb
sidekiq-statsd-0.1.1 vendor/ruby/1.9.1/gems/yard-0.8.6.1/lib/yard/server/static_caching.rb
sidekiq-statsd-0.1.0 vendor/ruby/1.9.1/gems/yard-0.8.6.1/lib/yard/server/static_caching.rb
yard-0.8.6.1 lib/yard/server/static_caching.rb
challah-1.0.0.beta2 vendor/bundle/gems/yard-0.8.6/lib/yard/server/static_caching.rb
challah-1.0.0.beta2 vendor/bundle/gems/yard-0.8.5.2/lib/yard/server/static_caching.rb
yard-0.8.6 lib/yard/server/static_caching.rb